Controller / Router Arguments

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Controller / Router Arguments

Daniel Khan-2
Hello List,

I am playing around with the controllers and I want to create a calendar.

So the best thing would be to have an URL like:
- http://www.mydomain.com/Calendar/2006/06/04

but I would also be satisfied with something like:
- http://www.mydomain.com/Calendar/show/year/2006/month/06/day/04

I have tested with this code:

class CalendarController extends Zend_Controller_Action {

     function indexAction() {
         // $this->_redirect('/');
     }

     function __call($id, $arguments) {
         $args = func_get_args();
         echo "<pre>";
         print_r($args);
         echo "</pre>";
     }
}

When I call
http://dienstplan.trendworxx.at/Calendar/2006/06/04

I get:
Array
(
     [0] => 2006Action
     [1] => Array
         (
         )

)


Calling
http://dienstplan.trendworxx.at/Calendar/show/year/2006/month/06/day/04

I get:
Array
(
     [0] => showAction
     [1] => Array
         (
         )

)

I think I am missing something here. I should at least get anything into
the [1] Array.

Thanks for your help!

--
Daniel Khan
Reply | Threaded
Open this post in threaded view
|

Re: Controller / Router Arguments

Simon Mundy
Hi Daniel

The second example you've provided is closer to the scheme provided by
the current implementation, but you can't simply receive the extra
params by using the second argument in the __call method. You need to
explicitly retrieve your params from the controller by:-

$year = $this->_getParam('year', 2006); // Where 2006 is a default value
echo $year;

or

$params = $this->_getAllParams();
echo $params['year'];

The first example is probably better practice, as it allows for fallbacks.

Cheers

> Hello List,
>
> I am playing around with the controllers and I want to create a calendar.
>
> So the best thing would be to have an URL like:
> - http://www.mydomain.com/Calendar/2006/06/04
>
> but I would also be satisfied with something like:
> - http://www.mydomain.com/Calendar/show/year/2006/month/06/day/04
>
> I have tested with this code:
>
> class CalendarController extends Zend_Controller_Action {
>
>     function indexAction() {
>         // $this->_redirect('/');
>     }
>
>     function __call($id, $arguments) {
>         $args = func_get_args();
>         echo "<pre>";
>         print_r($args);
>         echo "</pre>";
>     }
> }
>
> When I call
> http://dienstplan.trendworxx.at/Calendar/2006/06/04
>
> I get:
> Array
> (
>     [0] => 2006Action
>     [1] => Array
>         (
>         )
>
> )
>
>
> Calling
> http://dienstplan.trendworxx.at/Calendar/show/year/2006/month/06/day/04
>
> I get:
> Array
> (
>     [0] => showAction
>     [1] => Array
>         (
>         )
>
> )
>
> I think I am missing something here. I should at least get anything
> into the [1] Array.
>
> Thanks for your help!
>


--

Simon Mundy | Director | PEPTOLAB

""" " "" """""" "" "" """"""" " "" """"" " """"" " """""" "" "
202/258 Flinders Lane | Melbourne | Victoria | Australia | 3000
Voice +61 (0) 3 9654 4324 | Mobile 0438 046 061 | Fax +61 (0) 3 9654 4124
http://www.peptolab.com

Reply | Threaded
Open this post in threaded view
|

Re: Controller / Router Arguments

Daniel Khan-2
Simon Mundy wrote:

> $year = $this->_getParam('year', 2006); // Where 2006 is a default value
> echo $year;

> $params = $this->_getAllParams();
> echo $params['year'];

I understand - thank you very much!

--
Daniel Khan