manuakasam (1) [Avatar] Offline
Hello everyone,

recently i've been started to read through the book and so far it's been pretty great. In chapter 4 however i started to struggle...

On Page 87 within Places_Controller_Plugin_ViewSetup you access the $request Variable and it's methods.
Maybe i'm blind but up to this page, $request has not been initialized

As i came to know, $request is an instante of Zends getRequest() Method?
Is this true? Because in the source code all i could fine was one initialisation of $request in IndexController.php->menuAction()

I just want to know if there's something i've overlooked or if this is intended to appear way after page 87. If that would be the case it's kind of irritating and if this were to happen more often throughout the book it would be a huge pushback.

Any help will be appreciated!

best regards, sam
tyrsson (1) [Avatar] Offline
Re: Chapter 4 - $request - where is it defined?

$request is actually a protected controller action property as you can access the request object via a action controller like so:

$request = $this->_request;

Which means in your action controllers you can avoid the overhead of calling the method $this->getRequest() by using the syntax:

instead of:
$request = $this->getRequest();

$params = $this->_request->getParams();

In a deeper look you will find that the abstract controller action has the request injected in the construct().

Hope it helps