Shorten Zend Framework Route Definitions

前端 未结 3 676
佛祖请我去吃肉
佛祖请我去吃肉 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 11:52

    My routes.ini file started to get really large, so I decided to use Zend Caching to cache the routes after they had been parsed. I used Xcache for the backend caching solution. Here's the code, which should be put in the Bootstrap.php file:

    protected function _initRoutes()
    {
      $backendType = 'Xcache';
      $backendOptions = array();
    
      // Instantiate a caching object for caching the routes
      $cache = Zend_Cache::factory('File', $backendType, 
        array(
          'automatic_serialization' => true, 
          'master_files'=>array(APPLICATION_PATH . '/configs/routes.ini')
        ), 
        $backendOptions
      );
    
      $frontController = Zend_Controller_Front::getInstance();        
    
      if(! $router = $cache->load('router')) {
    
        // Load up .ini file and put the results in the cache
        $routes = new Zend_Config_Ini (APPLICATION_PATH . '/configs/routes.ini', 'production');            
        $router = $frontController->getRouter();
        $router->addConfig( $routes, 'routes' );
    
        $cache->save($router, 'router');
      }     
      else {        
        // Use cached version
        $frontController->setRouter($router);
      }
    
    }
    

提交回复
热议问题