0
votes

I'm writing an extension of url_for which will check that the logged in user has the appropriate credentials to access a link to a route before rendering said link.

I have determined how to get the Action from module/action strings, and successfully check the credentials required. But I can't find a reliable way to get the appropriate Action from the name of the route, whether a named route or one derived from pattern matching e.g.

 home/index => module: home, action: index
 @home      => module: home, action: index

I suspect I need to copy code from sfRouting, as I can't find a public method in Symfony to do this. Is there a better way?

1
Usually I would check in the template if the user has appropriate credentials before rendering the link. You can also leave all the work to Symfony - let users click the link and he/she will be redirected to an "unauthorized" page if they don't have sufficient permissions.Michal Trojanowski
As me i'll check in the controller if i have the right credentials else i redirect it to secure page.Haithem Rihane

1 Answers

0
votes

I tend to just use the route name for stuff like this:

<?php $route = $sf_context->getInstance()->getRouting()->getCurrentRouteName() ?>

<?php if ($route == 'home'): ?>
  <p>hello</p>
<?php endif ?>