Shorten Zend Framework Route Definitions

前端 未结 3 673
佛祖请我去吃肉
佛祖请我去吃肉 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条回答
  •  -上瘾入骨i
    2021-02-04 12:10

    When it comes to setting up routes like this, I use a config file. As a preference, I use XML to store my config data, however these could just as easily be stored in another supported format. I then add the routes from the config, to the router in my bootstrap.

    Config:

    
        
            
                :module/:id
                
                    index
                    index
                
                
            
            
                :module/:controller/:id
                
                    index
                
                
            
            
                :module/:controller/:action/:id
                
                    index
                    index
                
                
            
        
    
    

    Bootstrap

    $config = new Zend_Config_Xml('config.xml');
    $router = Zend_Controller_Front::getInstance()->getRouter();
    $router->addConfig($config, 'routes');
    

    Obviously, there are other options and I'd encourage you to read the documentation on this, however, this fits for your example.

提交回复
热议问题