Simple route with Zend framework 1.12

无人久伴 提交于 2019-12-04 12:51:58
Anil

I think this is the simple codes for routing in zend framework:

  • on index.php you should not touch anything. Leave it as it is from Zend default when you create a project

  • on projectHomeDirectory/application/Bootstrap.php include this:

    protected function _initRoutes()
    {
        $router = Zend_Controller_Front::getInstance()->getRouter();
        include APPLICATION_PATH . "/configs/routes.php";
    }
    
  • create a routes.php file under projectHomeDirectory/application/configs/ and add there all the routes you want, for example:

    $route = new Zend_Controller_Router_Route(
        'author',
        array(
            'controller' => 'user',
            'action'     => 'index'
        ) 
    );
    
    $router->addRoute('author', $route);
    

Of course you then need to create the UserController the User model the sample module and the views.

Useful link:

I use the router resource plugin, I find it convenient to add the routes to my config files (for example the application.ini).

You can find an example and more documentation on the ZF website:

http://framework.zend.com/manual/1.12/en/zend.application.available-resources.html#zend.application.available-resources.router

Good luck building your ZF application!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!