Search code examples
phpzend-frameworkzend-formzend-db

$this->action to Display a certain action from a controller - ZEND


I'm trying to build a menu for my website that I'm building with ZEND. I'm a newbie to ZEND. So, I created an action catmenuAction() in the controller called BlogCateogoriesController. I created a veiw script for it too.

now in the master.phtml file, I'm trying to call this view script to render my menu. Actually i think this is how I'll bring latest news, comments, Tweets to my pages (the way lika MODULES in Joomla do).

In my master.phtml file I declared

<?php $this->layout()->categoriesList = $this->action('catmenu', 'Blog_BlogCategories'); ?>

and now I'm getting this terrible error saying that it can't find Blog_BlogCategoriesController:

Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception' with message 'Invalid controller specified (Blog_BlogCategories)' in D:\Server\xampp\htdocs\zendtest\library\Zend\Controller\Dispatcher\Standard.php:248 Stack trace: #0 D:\Server\xampp\htdocs\zendtest\library\Zend\View\Helper\Action.php(135): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #1 [internal function]: Zend_View_Helper_Action->action('catmenu', 'Blog_BlogCatego...') #2 D:\Server\xampp\htdocs\zendtest\library\Zend\View\Abstract.php(350): call_user_func_array(Array, Array) #3 [internal function]: Zend_View_Abstract->__call('action', Array) #4 D:\Server\xampp\htdocs\zendtest\application\layouts\master.phtml(20): Zend_View->action('catmenu', 'Blog_BlogCatego...') #5 D:\Server\xampp\htdocs\zendtest\library\Zend\View.php(108): include('D:\Server\xampp...') #6 D:\Server\xampp\htdocs\zendtest\library\Zend\View\Abstract.php(888): Zend_View->_run('D:\Server\xampp...') #7 D:\Ser in D:\Server\xampp\htdocs\zendtest\library\Zend\Controller\Plugin\Broker.php on line 336

HELP ME OUT PLEASE!!!


Solution

  • Syntax for Zend_View_Helper_Action is this:

    action( string $action, string $controller, string $module = null, array $params = array() ) : string

    So where you call:

    $this->action('catmenu', 'Blog_BlogCategories');

    I assume you have a class Blog_BlogCategoriesController in the 'Blog' module. You would need to call:

    $this->action('catmenu', 'BlogCategories', 'Blog');