English 中文(简体)
添加Zentd的路由模块
原标题:Add router modules in Zend

我有这一法典:

$defaultAdmin = array ( module  =>  admin ,  controller  =>  index ,  action  =>  index  );
$routeAdmin = new Zend_Controller_Router_Route (  admin/:controller/:action/* , $defaultAdmin );
$router->addRoute (  admin , $routeAdmin );

然而,如果我进入这一档次:行政/行政,将控制员装上/申请/控制员/主计长。 php,而不是在申请/申请/模块/行政/控制人员/内部监督员中。

我的 full锁是:

abstract class My_Application_Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    /**
     * Inicializa las características generales de la aplicación
     *
     * @param $application Zend_Application|Zend_Application_Bootstrap_Bootstrapper         
     * @return void
     */
    public function __construct($application) {
        parent::__construct ( $application );
        $autoloader = $application->getAutoloader ();
        $autoloader->registerNamespace (  Busca  );
        $this->_initConfig ();
        $this->_initDb ();
        $this->_initView ();
        $this->_setCache ();
        $this->_setRouter ();
        $this->_setHelpers ();
        $this->_init ();
    }
    /**
     * Método que setea el cache del sistema
     *
     * @return My_Application_Bootstrap
     */
    protected function _setCache() {
        $config = Zend_Registry::get (  config  );

        $metadataBack = $config->metadata_cache->frontend->toArray ();
        $metadataFront = $config->metadata_cache->backend->toArray ();

        $memcachedOpts = $config->db_cache->toArray ();

        $memcache = new My_Cache_Backend_Memcached ( $memcachedOpts );
        $metadataCache = Zend_Cache::factory (  Core ,  File , $metadataBack, $metadataFront );

        Zend_Registry::set (  Cache , $memcache );
        Zend_Registry::set (  MetadaCache , $metadataCache );

        My_Model_Table_Abstract::setDefaultMetadataCache (  MetadaCache  );
        return $this;
    }
    /**
     * Inicializa la configuración de la aplicación
     *
     * @return My_Application_Bootstrap
     */
    protected function _initConfig() {
        Zend_Registry::set (  config , new Zend_Config ( $this->getOptions () ) );
        return $this;
    }
    /**
     * Inicializa la(s) base(s) de datos
     *
     * @return My_Application_Bootstrap
     */
    protected function _initDb() {
        $this->bootstrap (  multidb  );
        $resource = $this->getPluginResource (  multidb  );
        $databases = Zend_Registry::get (  config  )->resources->multidb;
        foreach ( $databases as $name => $adapter ) {
            $db_adapter = $resource->getDb ( $name );
            Zend_Registry::set ( $name, $db_adapter );
        }
        return $this;
    }
    /**
     * Reemplaza la vista Zend_View por My_View
     *
     * @return My_Application_Bootstrap
     */
    protected function _initView() {
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper (  viewRenderer  );
        $view = new My_View ();
        $viewRenderer->setView ( $view );
        return $this;
    }
    /**
     * Método que setea el router general del sitio
     * Todas las peticiones irán al controlador default, con excepción de las de
     * administración.
     *
     * @return My_Application_Bootstrap
     */
    protected function _setRouter() {
        $front = Zend_Controller_Front::getInstance ();
        $router = $front->getRouter ();
        /*
         * Router para entidades
         */
        $defaultSection = array ( module  =>  default ,  controller  =>  index ,  action  =>  section ,  sectionAction  => null,  section  => null,  id  => null,  title  => null );
        $requiredSection = array ( id  =>  d+  );
        $routeSection = new Zend_Controller_Router_Route (  :section/:sectionAction/:id/:title/* , $defaultSection, $requiredSection );
        $router->addRoute (  section , $routeSection );
        /*
         * Router para entidades sin ID
         */
        $defaultSection = array ( module  =>  default ,  controller  =>  index ,  action  =>  section ,  sectionAction  => null,  section  => null );
        $routeSection = new Zend_Controller_Router_Route (  :section/:sectionAction/* , $defaultSection, $requiredSection );
        $router->addRoute (  section , $routeSection );
        /*
         * Router para listados
         */
        $defaultList = array ( module  =>  default ,  controller  =>  index ,  action  =>  list ,  section  => null );
        $routeList = new Zend_Controller_Router_Route (  :section/listar/* , $defaultList );
        $router->addRoute (  listados , $routeList );
        /*
         * Router para administración
         */
        $defaultAdmin = array ( module  =>  admin ,  controller  =>  index ,  action  =>  index  );
        $routeAdmin = new Zend_Controller_Router_Route (  admin/:controller/:action/* , $defaultAdmin );
        $router->addRoute (  admin , $routeAdmin );
        return $this;
    }
    /**
     * Configuración de los helpers del sistema
     *
     * @return My_Application_Bootstrap
     */
    protected function _setHelpers() {
        $prefix =  My_Controller_Action_Helpers ;
        Zend_Controller_Action_HelperBroker::addPrefix ( $prefix );
        Zend_Controller_Action_HelperBroker::addPath ( APPLICATION_PATH .  /controllers/helpers ,  My_Controller_Action_Helper  );
        return $this;
    }
    /**
     * Para usar en los hijos en vez del constructor
     */
    protected function _init() {

    }
}
最佳回答

创建一套新目录,以备应用,编号:cut,贴上您的应用程序/控制器。 然后确保你提出申请。 iii

resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules = true;

如果您在申请夹中保留控制器的目录,那么,zf将不使用模块结构,从而保证您的切割和过去。

问题回答

一旦您具备模块结构,就一定会为你的模块设置一个boot锁,使其与您的习俗路线相连接。 例如

class Example_Bootstrap extends Zend_Application_Module_Bootstrap
    {

    public function _initModuleRoutes()
    {
        $this->bootstrap( FrontController );
        $frontController = $this->getResource( FrontController );
        $router = $frontController->getRouter();

        $route = new Zend_Controller_Router_Route(
             modulename/:action/* ,
            array(
                     module  =>  modulename ,
                     controller  =>  modulecontroller ,
                     action  =>  index 
            )
        );
        $router->addRoute( routename , $route);

        return $router;
    }




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签