On Thu, Mar 17, 2011 at 3:16 AM, Peter Sharp <str...@hotmail.com> wrote:

> protected function _initSettings()
>    {
>        // Retrieve the view
>        $this->bootstrap('layout');
>        $layout = $this->getResource('layout');
>        $view = $layout->getView();
>

If you look at the source of Zend_Layout#getView(), it attempts to load the
view instance from the "viewRenderer" action helper. At this point, the
viewRenderer doesn't have a view instance yet, so Zend_Layout calls
$viewRenderer->initView() which ends up creating a new view instance --
which doesn't have your prefix paths.

The proper way to access the view instance is to pull it from the bootstrap.
Change those 3 lines to this and you should be set:

$this->bootstrap('view');
$view = $this->getResource('view');


>         // Register Custom URL Handler
>        $urlHelper = new Custom_Controller_Action_Helper_Url();
>        Zend_Controller_Action_HelperBroker::addHelper($urlHelper);
>
       // Create ACL and add the ACL action helper
>        $acl = new Custom_Acl();
>        $aclHelper = new Custom_Controller_Action_Helper_Acl(null,
> array('acl' => $acl));
>        Zend_Controller_Action_HelperBroker::addHelper($aclHelper);
>
>        // Create the site navigation object
>        $nav_config = new Zend_Config_Xml(APPLICATION_PATH .
> '/configs/navigation.xml', 'nav');
>        $nav_config = $this->_extrapolateAcl($nav_config->toArray());
>        $navigation = new Zend_Navigation($nav_config);
>
>        $role = Zend_Auth::getInstance()->getIdentity();
>        if(null == $role)
>            $role = 'guest';
>        else
>            $role = $role->role;
>
>        // Attach navigation to the view
>        $view->navigation($navigation)->setAcl($acl)->setRole($role);
>
>
At this point, the navigation helper will add the
Zend_View_Helper_Navigation prefix/path if it is not already registered. If
you bootstrap the view prior to calling this, your prefix paths should
already be set up correctly. You can verify by doing a var_dump() of
$view->getPrefiPaths().


>        // Other view configuration
>        $view->addHelperPath('Zend/View/Helper/Navigation',
> 'Zend_View_Helper_Navigation');
>        $view->addHelperPath('Custom/View/Helper', 'Custom_View_Helper');
>

You don't need to add helper paths here since they were already added in
application.ini and you should now be using a single Zend_View instance
throughout your application. If you decide to keep this code in
_initSettings instead of using application.ini, move these lines towards the
top of this method (before calling $view->navigation()).


>        $view->doctype('HTML5');
>
>
   }
>

--
*Hector Virgen*
Sr. Web Developer
http://www.virgentech.com

Reply via email to