Skip to content

Commit d7d69b2

Browse files
authored
Update override-decorate-controller.md
Ajax calls not working with decorated controllers; mention to clarify the need of implementing the decorated controller action methods
1 parent 2a4be4e commit d7d69b2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/content/1.7/modules/concepts/controllers/admin-controllers/override-decorate-controller.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,20 @@ However we could modify the input request or the output given by decorated contr
159159
}
160160
```
161161

162+
In order for the DemoController to work, we also need to implement all the other Action methods we don't interfere with of the decorated controller and simply return the decorated controller method. Example:
163+
164+
```php
165+
<?php
166+
public function anAction($id, Request $request)
167+
{
168+
return $this->decoratedController->anAction($id, $request);
169+
}
170+
171+
```
172+
173+
On some edge cases we might need to perform an Ajax call from our Javascript file (or the Twig template) to our decorating DemoController.
174+
Curently this will not work though, what we need to do in such a case is to create a regular admincontroller e.g. mymodule/src/Controller/Admin/DemoAjaxController.php with a method, create a route for that method in our mymodule/src/config/routes.yml, generate the URL as described here, [symfony docs](https://devdocs.prestashop.com/1.7/modules/concepts/controllers/admin-controllers/route-generation/) and perform our ajax call using the resulting Symfony route.
175+
162176

163177
{{% notice tip %}}
164178
If you have trouble writing the right service configuration for your decoration, you can use Symfony debugger to dump the routes with `php bin/console debug:container`. It can also be helpful to find the service ID of the controller.

0 commit comments

Comments
 (0)