0

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

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

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 = "索引"

routes.interet.map.1 = "搜索引擎优化"

routes.interet.map.2 = "id"

routes.interet.reverse ="i/%s/%d/"

我的 .htaccess :

重写引擎开启

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

重写规则 ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

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

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

我忘记了像 addRoute 或其他东西这样的东西吗?

我已经在我的引导程序中尝试过这种方法:

    $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);

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

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

谢谢

4

3 回答 3

0

通常,您的 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

注意每一行如何以资源开头,第四个单词是路由的“名称”(在本例中是'login')。

我不是 100% 确定,但我不认为你的引导程序_initRouter()在这里帮助你,我不记得当路由在application.ini. 也许把它评论出来,看看它是否有帮助。

于 2013-04-08T04:15:53.003 回答
0

我已经在我的引导程序中尝试过这种方法:

    $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);

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

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

于 2013-04-08T05:36:20.357 回答
0

问题是正则表达式:

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

代替

"/i/([-\w]+)/(\d+)/"
于 2013-04-08T15:17:02.893 回答