views:

59

answers:

1

Let's say I have 2 controllers, content and news:

class ContentController extends Zend_Controller_Action { }

and

class NewsController extends ContentController { }

If there are no views found for the news controller, I want Zend to use the scripts path of its parent controller. How can I achieve this without having to route to its parent controller?

+1  A: 

You will have to add the scriptPath manually:

class ContentController extends Zend_Controller_Action { 

   public function init()
   {
      $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/content');
   }

}

and

class NewsController extends ContentController {

   public function init ()
   {
       // Ensure that ContentController inits.
       parent::init();
      $this->view->addScriptPath(APPLICATION_PATH . '/views/scripts/news');
   }
}

This will use the stack functionality of the view script inflector. It will first look in the path last specified, which is APPLICATION_PATH . '/views/scripts/news', if the script isn't found there, it will look in the second directory on the stack, which is APPLICATION_PATH . '/views/scripts/content'.

PatrikAkerstrand