Hi,

Well i ended up writing a simple view helper that i have been using in my
views like:

        <?php if($this->canRoleViewActionLink('/articles/edit')): ?>
                                                <td>
                                                         "<?php echo $this- 
url(array('controller' => 'articles', 'action' =>
'edit', 'articleID' => $article->getId())); ?>">Edit 
                                                </td>
                                        <?php endif; ?>

...where the view helper queries the acl to see if the role has the
privileges to perform the action. If not, the link is not rendered:

class My_View_Helper_CanRoleViewActionLink extends Zend_View_Helper_Abstract 
        {
                public function canRoleViewActionLink($location){               
        
                        $actionName = basename($location);
                        $controllerName = dirname(ltrim($location, '/'));
                        
                        $auth = Zend_Auth::getInstance();
                        $acl = new My_Model_Acl_Site(); 

                        if($auth->hasIdentity()){
                                $identity = $auth->getIdentity();
                                
                                if(!$acl->has($controllerName)){
                                        //resource doesn't exist in acl, 
therefore not a restricted resource -
can be viewed
                                        return true;
                                }
                                if($acl->isAllowed($identity->role, 
                                                                   
$controllerName, 
                                                                   
$actionName)){
                                        return true;
                                }else{
                                        return false;
                                }       
                        }       
                        //no auth, therefore assume manual visit of link        
        
                        return false;
                }
        }

...so that's working so far, but ideally i was hoping for some way of
integrating the acl into the link without the use of a separate view helper,
the way that Zend_Nav does it. Is there any way of adding an acl/role
parameter to the uri view helper, so the above can be achieved more simpler
in something like the following manner:

"<?php echo $this- url(array('controller' => 'articles', 'action' => 'edit',
'articleID' => $article->getId(), 'role' => $auth->getRole(), 'resource' =>
'article')); ?>">Edit 


ps. is there any way to post links on here without them being rendered as
links? like a code button? 
-- 
View this message in context: 
http://n4.nabble.com/Zend-Nav-acl-for-individual-links-tp1593312p1676633.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to