2008年8月11日星期一

[fw-mvc] Url helpers

Hi,

I have a problem with both url helpers Zend_Controller_Action_Helper_Url
and Zend_View_Helper_Url. First of all my default route looks like this:

$frontController->getRouter()->addRoute('default',
new Zend_Controller_Router_Route(
':mandator/:lang/:controller/:action/*',
array(
'mandator' => 'site',
'lang' => 'de',
'module' => 'default',
'controller' => 'index',
'action' => 'index',
))
);

Then I have a the method JobController::showAction which is called for a
routes like these:

/site/de/job/show/id/21
/customer/en/job/show/id/21

This works if the job with id 21 exists. If the job does not exist then
JobController::showAction should redirect to JobController::listAction
and clear the id param in the url.


Solution A:

$this->_redirect($this->getHelper('url')->url(array(
'controller' => 'job', 'action' => 'list'), null, true)
);

The id param is removed from the url so I get these redirections:

/site/de/job/show/id/99999 => /site/de/job/list
/customer/en/job/show/id/99999 => /site/de/job/list

As you can see the values for :mandator and :lang are set back to the
defaults. :-(


Solution B:

$this->_redirect($this->getHelper('url')->url(array(
'controller' => 'job', 'action' => 'list', 'id' => null))
);

Now I get these redirections

/site/de/job/show/id/99999 => /site/de/job/list/id
/customer/en/job/show/id/99999 => /customer/en/job/list/id

As you can see the values for :mandator and :lang are kept, but there is
still the :id param left over with now value. :-(


Solution C:

Now I am looking for the correct solution to get these redirects:

/site/de/job/show/id/99999 => /site/de/job/list
/customer/en/job/show/id/99999 => /customer/en/job/list

How can I archive this? Why is a "'id' => null" not removing the 'id'
parameter. And by the way, I get the same problems with the url view helper.

Thanks for your help and Best regards,

Ralf

没有评论: