views:

89

answers:

2

Currently I'm creating a controller (ZendFramework) that gets from database an URL string by given id.

/linker/show/id/6

I.e. id=6 /products/list/type/games.

In LinkerController I would use _forward() method to pass also optional params (POST, GET), but this method takes parameters such like ($action, $controller, $module, $params) and my string /products/list/type/games right now is not valid.

I also do not want to redirect to this URL (user should not see that he is in ProductController).

Any ideas how to solve it ?

+1  A: 

You can't forward to URL (because of the nature of forwarding - creating a new internal request object). You can only forward to request (module, controller, action).

Use redirecting insted (in controller):

$this->_helper->redirector->gotoUrlAndExit($url);
Tomáš Fejfar
Redirect is not the correct way - as I said, I preffer not to show user a destiny URL.
hsz
then you need to forward to request - not URL. i.e.: module, controller, action, params as you've written above. There is NO OTHER WAY. You can't forward to URL (it's no need to, to be honest).
Tomáš Fejfar
+1  A: 

This is tricky. You want a mash-up between a redirect and a forward.

Working backwards:

  1. You need to call $this->_forward( $action, $controller, $module, $params )

  2. So, you need to store these four parameters in your linker table ($params would be serialized)

Then, your linker code might look like:

public function showAction()
{
  $linker_table = new LinkerTable();
  $link = $linker_table->find(array('id' => $this->_getParam('id')));

  // first, try to forward, if all settings are there
  if ( $link && $link->hasForwardSettings() ) {
    $this->_forward( $link->action, $link->controller, $link->module, unserialize($link->params));
    return;
  }

  // perhaps other links can just be straight redirects, so then $this->_redirect($link->url)
}

Either that or some mod_rewrite magic.

Derek Illchuk
This way I have to set separatly all of the params: `action, controller and module`.Is there any way to set only one URL `/products/list/type/games` and explode it to this 3 params ? Any magic ZF method ? ;)
hsz