Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Zend Framework: How to get default param?

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?


1 Answers

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);
like image 109
vartec Avatar answered Dec 08 '25 19:12

vartec