> On Jan 24, 2015, at 15:24, Ariel Lu <
ariellur...@gmail.com> wrote:
>
> Hello! I've just started using Aura2 to play around on the weekends, there's things I like and MANY I don't understand from this framework, so I thought I could bother you with one question from the top of my head.
>
> I'm reading about dispatching as a microframework, so I need this functions to start a route and a dispatcher :
>
> public function define(Container $di)
> public function modify(Container $di)
>
> and on my action:
>
> public function __construct(Request $request, Response $response)
>
> which receives
>
>
> $di->get('aura/web-kernel:request');
> $di->get('aura/web-kernel:response');
>
> So it seems to me I'm passing this variable $di around all the time, and my question is why?
If you have not done so already, you should read the documentation on the dependency injection package: <
https://github.com/auraphp/Aura.Di>
Using a DI container can be a hard subject to grasp, but in short, you don't pass the $di instance around. Instead, all of the object creation happens *inside* the $di instance.
Regarding your action, you say you define your class like this ...
class MyAction
{
public function __construct(Request $request, Response $response)
{
// ...
}
}
... which is just fine, but the part you need now is to set up the the container configuration (this is the config/Common.php file at the top level of the project):
class Common
{
public function define(Container $di)
{
$di->params['MyAction']['request'] = $di->get('aura/web-kernel:request');
$di->params['MyAction']['response'] = $di->get('aura/web-kernel:response');
}
}
Let me know if that begins to help.
--
Paul M. Jones
pmjo...@gmail.com
http://paul-m-jones.com
Modernizing Legacy Applications in PHP
http://mlaphp.com