I would like to display navigation based on* who* you are. Here is what I've
done in a view_helper, though it would be great to integrate this into my
Acl since I'm checking user roles against it every request already.

Ralph, could you elaborate a bit on : "I would probably implement the Role &
Resource_Interfaces on my models, and do the acl checks.

You could also do some kind of view iteration of the navigation object and
then pass data into a custom built ACL, I would be interested to see if that
kind of solution had merit."

Thanks a lot. It is a huge benefit having access to some of the guys at
Zend. Makes it hard to think about coding anything else.

<?php

class Zend_View_Helper_Navigation extends Zend_View_Helper_Abstract {

    public function navigation() {

        if(Zend_Auth::getInstance()->hasIdentity()) {
            $role = Zend_Auth::getInstance()->getIdentity()->role;
        } else {
            $role = 'guest';
        }

        switch ($role) {

            case 'guest' :
                return null;
                break;

            case 'user' :
            case 'admin' :
                $ctrl = Zend_Controller_Front::getInstance();
                $controller = $ctrl->getRequest()->getControllerName();
                return $this->view->partial('navigation.phtml',
array('controller', $controller));
                break;

            default:
                return null;
        }
    }

}


On Tue, Jul 14, 2009 at 7:40 PM, Ralph Schindler
<ralph.schind...@zend.com>wrote:

> The question becomes what do you want to hide/show navigation based on?
>
> Is it based on where you currently are in an application (which
> controller/action/module?)
>
> Or is it based on who you are? User/Group information?  If its the latter,
> I would probably implement the Role & Resource_Interfaces on my models, and
> do the acl checks.
>
> You could also do some kind of view iteration of the navigation object and
> then pass data into a custom built ACL, I would be interested to see if that
> kind of solution had merit.
>
> -ralph
>
> J DeBord wrote:
>
>> Ahh, I did not realize there was a Zend_View_Helper_Navigation. Thus when
>> I instantiate my Acl class it in the bootstrap it loads
>> Zend_View_Helper_Navigation from the library/Zend folder, while in my layout
>> script it is loading from my application/views/helpers folder. Since I
>> prefix my custom view helpers with Zend_View_Helper and throw them into the
>> /helpers directory, it works in the view, but in the bootstrap, only the
>> library/Zend folder is being searched.
>>
>> How should I get around this? Or would it just be best to rename /my/
>> Navigation view helper?
>>
>> Also, and perhpas more importantly, how can an Acl class even know about
>> what is in the application/views/helpers folder??? Hmm.
>>
>> Nice catch Ralph. Thanks.
>>
>> J
>>
>>
>> On Tue, Jul 14, 2009 at 5:41 PM, Ralph Schindler <
>> ralph.schind...@zend.com <mailto:ralph.schind...@zend.com>> wrote:
>>
>>    Hmm, are you sure that you are loading the correct object? Where is
>>    this code located? I notice that it implements
>>    Zend_Acl_Resource_Interface, but there is already a class called
>>    Zend_View_Helper_Navigation being loaded by the framework already
>> right?
>>
>>    Where is your custom code being stored?
>>
>>    -ralph
>>
>>
>>    J DeBord wrote:
>>
>>        I'm experimenting with Zend_Acl and even though what I am doing
>>        may not be the best way to go about hiding/displaying
>>        navigation, the error message below does not appear to be correct:*
>>
>>        Catchable fatal error*: Argument 1 passed to Zend_Acl::add()
>>        must implement interface Zend_Acl_Resource_Interface, instance
>>        of Zend_View_Helper_Navigation given
>>
>>        As you can see, Zend_View_Helper_Navigation does indeed
>>        implement Zend_Acl_Resource_Interface
>>
>>        What do you guys think?
>>
>>        <?php
>>
>>        class Zend_View_Helper_Navigation extends
>>        Zend_View_Helper_Abstract implements Zend_Acl_Resource_Interface {
>>             protected $resourceId = 'navigation';
>>             public function navigation() {
>>                     return $this->view->partial('navigation.phtml',
>>        array());
>>             }
>>             /**
>>            * (non-PHPdoc)
>>            * @see
>>
>>  library/Zend/Acl/Resource/Zend_Acl_Resource_Interface#getResourceId()
>>            */
>>           public function getResourceId() {
>>               return $this->_resourceId;
>>           }
>>
>>        }
>>
>>
>>

Reply via email to