Redirect url to custom url using .htaccess or bootstrap in ZF1

时间:2017-08-04 12:28:38

标签: php zend-framework zend-route

I'm working with Zend Framework 1.9 and facing some problems with the routes. Actually, looking for a way to route url to custom one (url), but unfortunately couldn't find a solution after surfing on internet as well as on Stack Overflow.

Well, the problem is that the defined url is working fine: http://example.com/user/detail/code/hsg45464

but, I want to change the above url to custom url, something like this: http://example.com/[user_name]/[course]/[cource_description]

So, is there any possibility to achieve this custom url in Zend Framework 1.9 (.htaccess or bootstrap).

Cheers!

1 个答案:

答案 0 :(得分:0)

我希望在Bootstrap.php而不是更改configindex.php.htaccess

中的任何内容
## /application/Bootstrap.php ##

protected function _initRoutes()
{
    $frontController = Zend_Controller_Front::getInstance();
    $router = $frontController->getRouter();

    $router->addRoute('user-course', new Zend_Controller_Router_Route('/:username/:course/:desc', array(
        'controller' => 'default_controller_name',
        'action' => 'default_action_name'
    )));
}

之后,您需要创建一个控制器和一个视图来呈现它。

此外,您可以详细浏览Zend Framework 1.9的路由文档,因此这里是链接:Zend Framework 1.9 Routing