0
votes

I would like to use Zend_Controller_Router_Rewrite to rewrite my URL ndd.dev/interet/index/id/1/ for ndd.dev/i/rouen/1/ with zend 1.12

For this I have add in my bootstrap :

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

}

into my "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/"

my .htaccess :

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

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

But www.ndd.dev/i/rouen/1/ returns :

Zend_Controller_Dispatcher_Exception Invalid controller specified (i) envoyée dans /www/library/Zend/Controller/Dispatcher/Standard.php à la ligne 248

have I forgoten smoething like addRoute or something else ?

I've tried this method in my 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);

and same result, he tries to found "i" controler

*Zend_Controller_Dispatcher_Exception Invalid controller specified (i)*

Thanks

3
Do you have another route also called 'interet'?Tim Fountain
The problem was the regex : "i/([-\w]+)/(\d+)" instead of "/i/([-\w]+)/(\d+)/"Paul

3 Answers

0
votes

Typically your application.ini routes will conform to the structure (yours don't, unless you truncated them) :

// /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

note how each line starts with resource and the fourth word is the "name" of the route (in this case it's 'login').

I'm not 100% sure but I don't think your bootstrap _initRouter() is helping you here, I don't remember needing this when the routes are defined in the application.ini. Maybe comment it out and see if it helps.

0
votes

I've tried this method in my 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);

and same result, he tries to found "i" controler

*Zend_Controller_Dispatcher_Exception Invalid controller specified (i)*

0
votes

The problem was the regex :

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

instead of

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