简体   繁体   English

在zend Framework URL Rewrite中需要帮助

[英]Need Help in zend framework URL Rewrite

I need help in URL rewrite in zend framework. 我需要zend框架中的URL重写方面的帮助。 If I print below URL : 如果我在URL下打印:

echo $this->url(array('controller'=>'guestbook','action'=>'edit','id'=>$entry->id), null, TRUE);

It will generate url like : http://localhost/guestbook/public/index.php/guestbook/edit/id/1 它将生成如下网址: http://localhost/guestbook/public/index.php/guestbook/edit/id/1

But How can I generate url like : http://localhost/guestbook/public/index.php/guestbook/edit/1 in zend framework? 但是如何在zend框架中生成类似http://localhost/guestbook/public/index.php/guestbook/edit/1的 url?

I don't want 'id' in URL. 我不想要网址中的“ id” Please Help. 请帮忙。

Zend Controller Router will help you achive this . Zend Controller Router将帮助您实现这一目标。

The easyest way to get started would be at bootstrap add the following ( not realy tested but it should work with minimal debuging, see the link provided as it explains a ton more, use this code just to get started on understanding how routes work ) : 最简单的入门方法是在引导程序中添加以下内容(未经实际测试,但应在最少的调试下工作,请参阅提供的链接,因为它解释了很多内容,请使用此代码来开始了解路由的工作原理):

$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute(
    'guestbook_edit',
    new Zend_Controller_Router_Route('guestbook/edit/:id',
                                     array('controller' => 'guestbook',
                                           'action' => 'edit'))
);

To make it work you need to define a custom route, called eg guestbook, and make url helper to use it for your particular url. 为了使它起作用,您需要定义一个自定义路由,例如guestbook,并使URL辅助程序将其用于您的特定URL。

For example, in your application.ini you can define it as follows: 例如,在application.ini中,您可以按以下方式定义它:

resources.router.routes.guestbook.route = '/guestbook/edit/:id'
resources.router.routes.guestbook.defaults.controller = user
resources.router.routes.guestbook.defaults.action = edit
resources.router.routes.guestbook.defaults.id = 
resources.router.routes.guestbook.reqs.id = "\d+" 

Then, you use the url helper in the following way: 然后,您可以通过以下方式使用url帮助器:

echo $this->url(array('controller'=>'user','action'=>'edit','id'=>2), 'guestbook', TRUE);

Hope that helps. 希望能有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM