Skip to content

Commit b8f75a7

Browse files
authored
Update README.md
1 parent 7589a7d commit b8f75a7

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ $loader = new Psr4ClassLoader();
195195
$loader->addPrefix('Ajax\\', __DIR__.'/lib/phpmv/php-mv-ui/Ajax');
196196
$loader->register();
197197
```
198-
####Injection of the service
198+
####Library loading
199199
Create 2 services in the **app/config/services.yml** file :
200200
* The first for the JsUtils instance
201201
* The second for the controller
@@ -213,3 +213,30 @@ services:
213213
class: AppBundle\Controller\DefaultController
214214
arguments: ['@service_container','@jquery']
215215
```
216+
####Injection of the service
217+
It is then possible to inject the Symfony container and the JsUtils service in the controller constructor :
218+
219+
```php
220+
namespace AppBundle\Controller;
221+
222+
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
223+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
224+
use Symfony\Component\DependencyInjection\ContainerInterface;
225+
use Ajax\php\symfony\JsUtils;
226+
use AppBundle\AppBundle;
227+
228+
/**
229+
* @Route(service="app.default_controller")
230+
*/
231+
class DefaultController extends Controller{
232+
/**
233+
* @var Ajax\php\symfony\JsUtils
234+
*/
235+
protected $jquery;
236+
237+
public function __construct(ContainerInterface $container,JsUtils $js){
238+
$this->container=$container;
239+
$this->jquery= $js;
240+
}
241+
}
242+
```

0 commit comments

Comments
 (0)