Shorten Zend Framework Route Definitions

前端 未结 3 679
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-04 11:46

How can I shorten the definition of my custom routes in Zend Framework? I currently have this as definition:

$route = new Zend_Controller_Router_Route(
    \":mo         


        
3条回答
  •  旧巷少年郎
    2021-02-04 12:05

    I prefer to use *.ini files over XMLs especially when using Zend since it's more Zend-like and much more light-weight and compact. Here's an almost similar configuration using Zend_Config_Ini().

    application.ini

    [routes]
    routes.shortcutone.route=:module/:id
    routes.shortcutone.defaults.controller=index
    routes.shortcutone.defaults.action=index
    routes.shortcutone.reqs=\d+
    

    bootstrap.php

    $config = new Zend_Config_Ini('application.ini', 'routes');
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addConfig($config, 'routes');
    

    Take note that the [routes] section in the application.ini file can be renamed. And when it is renamed, the second parameter of Zend_Config_Ini() should reflect the new section title.

提交回复
热议问题