Zend Framework - how to rewrite url to seo friendly url

眉间皱痕 提交于 2019-12-05 20:18:12

In your bootstrap, you'll need to configure some "routes". So, if your bootstrap ends something like this:

$frontController = Zend_Controller_Front::getInstance();
$frontController->dispatch();

you can just add in some route definitions like this:

$frontController = Zend_Controller_Front::getInstance();

$router = $frontController->getRouter();
$router->addRoute( 'mylovelyroute',
    new Zend_Controller_Router_Route_Static( 'for-fun-link',
        array( 'controller' => 'test', 'action' => 'about' )
    )
);
$router->addRoute( 'myotherroute',
    new Zend_Controller_Router_Route_Static( 'about-product',
        array( 'controller' => 'page', 'action' => 'about' )
    )
);
$router->addRoute( 'justonemore',
    new Zend_Controller_Router_Route_Static( 'another/longer/path',
        array( 'controller' => 'mycontroller',
            'action' => 'myaction',
            'someparameter' => 'foo'
        )
    )
);

$frontController->dispatch();

The first parameter of addRoute() is just a unique name. Zend_Controller_Router_Route_Static takes the path you'd like to capture, and then an array of parameters, including a controller and action (and module if it applies).

If you wanted to add complexity, you could load the routes out of a database, or start using more dynamic routes. The docs here are a useful next step: http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.standard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!