Zend_Controller_Router_Rewrite和

我想使用Zend_Controller_Router_Rewrite来重写我的URL ndd.dev/interet/index/id/1/ for ndd.dev/i/rouen/1/ with zend 1.12

为此,我添加了我的引导程序:

protected function _initRouter () {

    $config = new Zend_Config_Ini(APPLICATION_PATH.'/config/application.ini', APPLICATION_ENV);
    $router = new Zend_Controller_Router_Rewrite();
    $router->addConfig($config, 'routes');

}

进入我的“application.ini”:

routes.interet.type =“Zend_Controller_Router_Route_Regex”routes.interet.route =“/ i /( . )/([0-9])/”routes.interet.defaults.controller =“interet”routes.interet.defaults . action =“index”routes.interet.map.1 =“seo”routes.interet.map.2 =“id”routes.interet.reverse =“i /%s /%d /”

我的.htaccess:

RewriteEngine On RewriteCond% -s [OR] RewriteCond% -l [OR] RewriteCond% -d RewriteRule ^ . * $ - [NC,L] RewriteRule ^ . * $ index.php [ NC,L]

www.ndd.dev/i/rouen/1 /返回:

Zend_Controller_Dispatcher_Exception指定的控制器无效(i)envoyéedans/www/library/Zend/Controller/Dispatcher/Standard.phpàlaligne 248

我是否忘记了像addRoute或其他东西一样的流露?

我在我的bootstrap中试过这个方法:

$router = Zend_Controller_Front::getInstance()->getRouter();

    $r = new Zend_Controller_Router_Route_Regex(
        "/i/([-\w]+)/(\d+)/",
        array('controller' => 'interet', 'action' => 'index'), 
        array(1 => 'seo', 2 => 'id'),
        'i/%s/%d/'
    );

    $router->addRoute('interet', $r);

同样的结果,他试图找到“我”的控制器

  • Zend_Controller_Dispatcher_Exception指定的控制器无效(i)*

谢谢

回答(3)

3 years ago

通常,您的application.ini路由将符合结构(您的不会,除非您截断它们):

// /application/configs/application.ini
//uri for this route
resources.router.routes.login.route = /login
//module for the route, 'default' is used if there is no named module
resources.router.routes.login.defaults.module = default
//default controlle for this route
resources.router.routes.login.defaults.controller = auth
//default action for this route
resources.router.routes.login.defaults.action = login

注意每行如何以 resource 开头,第四个字是路线的 "name" (在这种情况下是'login') .

我认为你的bootstrap _initRouter() 在这里帮助你,我不记得在 application.ini 中定义路线时需要这个 . 也许评论它,看看它是否有帮助 .

3 years ago

我在我的bootstrap中试过这个方法:

$router = Zend_Controller_Front::getInstance()->getRouter();

    $r = new Zend_Controller_Router_Route_Regex(
        "/i/([-\w]+)/(\d+)/",
        array('controller' => 'interet', 'action' => 'index'), 
        array(1 => 'seo', 2 => 'id'),
        'i/%s/%d/'
    );

    $router->addRoute('interet', $r);

同样的结果,他试图找到“我”的控制器

  • Zend_Controller_Dispatcher_Exception指定的控制器无效(i)*

3 years ago

问题是正则表达式:

"i/([-\w]+)/(\d+)"

代替

"/i/([-\w]+)/(\d+)/"