Tuesday, May 8, 2012

How to check if a controller exists using Zend Framework

Have you ever wondered how to check if a controller/action exist in zend FM from any side of app ? Here is the code

        $front = Zend_Controller_Front::getInstance();
        $dispatcher = $front->getDispatcher();

        $test = new Zend_Controller_Request_Http();
        $test->setParams(array(
            'action' => 'index',
            'controller' => 'content',

                )
        );

        if($dispatcher->isDispatchable($test)) {
            echo "yes-its a controller";
            //$this->_forward('about-us', 'content'); // Do whatever you want
        } else {
            echo "NO- its not a Controller";
        }



No comments:

Post a Comment