Skip to content

Commit 905fb3f

Browse files
authored
Update README for symfony 4
1 parent 9f979c7 commit 905fb3f

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,49 @@ $loader = new Psr4ClassLoader();
224224
$loader->addPrefix('Ajax\\', __DIR__.'/lib/phpmv/php-mv-ui/Ajax');
225225
$loader->register();
226226
```
227-
#### Injection of the service
227+
228+
229+
#### Symfony 4
230+
231+
Create a service inheriting from `JquerySemantic`
232+
```php
233+
namespace App\Services\semantic;
234+
235+
use Ajax\php\symfony\JquerySemantic;
236+
237+
class SemanticGui extends JquerySemantic{
238+
}
239+
```
240+
Check that autowiring is activated in **config/services.yml**:
241+
```yml
242+
services:
243+
# default configuration for services in *this* file
244+
_defaults:
245+
autowire: true # Automatically injects dependencies in your services.
246+
```
247+
You can then use dependency injection on properties, constructors or setters:
248+
249+
```php
250+
namespace App\Controller;
251+
252+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
253+
use App\Services\semantic\SemanticGui;
254+
255+
BarController extends AbstractController{
256+
/**
257+
* @var SemanticGui
258+
*/
259+
protected $gui;
260+
261+
public function loadViewWithAjaxButtonAction(){
262+
$bt=$this->gui->semantic()->htmlButton('button1','a button');
263+
$bt->getOnClick("/url",'#responseElement');
264+
return $this->gui->renderView("barView.html.twig");
265+
}
266+
}
267+
```
268+
#### Symfony 3
269+
##### Injection of the service
228270
Create 2 services in the **app/config/services.yml** file :
229271
* The first for the JsUtils instance
230272
* The second for the controller

0 commit comments

Comments
 (0)