How do I get the 'default' param if not specified?
Consider the following:
http://localhost/controller/action/id/123
In my controller, I can get the value of 'id' using
$request = $this->getRequest();
$id = $request->getParam('id');
If the URL is
http://localhost/controller/action/456
how do I get the value of 456? What is the 'param' name?
By default ZF URL have to follow pattern:
/controller/action/param1Name/param1Val/param2Name/param2Val ...
You should use router. For example in bootstrap.php:
$frontController = Zend_Controller_Front::getInstance();
//^^^this line should be already there
$router = $frontController->getRouter();
$route = new Zend_Controller_Router_Route(
'yourController/yourAction/:id',
array(
'id' => 1, //default value
'controller' => 'yourController',
'action' => 'yourAction'
),
array('id' => '\d+')
);
$router->addRoute('yourController', $route);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With