Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Symfony 4 | Get config parameters from controller within a custom bundle

$
0
0

I'm trying to get some params from a config yaml file, Im doing the following:

namespace ExampleVendor\AdminBundle\Controller;

/**
 * @Route("/", name="_home")
 */
public function index(ParameterBagInterface $params) {
    $menuIcons = $this->getParameter('admin-aside-menu');
    dump($menuIcons);

    return $this->render('@ExampleVendorAdminBundle/index.html.twig');
}

As you can see is just a dump function that prints the admin-aside-menu parameter, the problem is, this code works when it is in a controller in App\src\Controller, I mean in the "main" application src folder, but when I copy this code and paste it in a controller inside a custom bundle (something like vendor/myVendor/myBundle/src/Controller) I get an error when reloading the page:

Could not resolve argument $params of "ExampleVendor\AdminBundle\Controller\AdminController::index()", maybe you forgot to register the controller as a service or missed tagging it with the "controller.service_arguments"?

I need ParameterBagInterface to get those parameters but I dont know how to "inject" it in my controller.

Thank you for reading.

---------------------- EDIT ----------------------

Okay so it seems like this post says how to fix this issue but, since the controller I need to inject something is in a custom bundle in the vendor folder, the answer doesn't help me at all

Project
|
+--AdminBundle <- My custom bundle, installed via composer as symlink
|  |
|  +--Controller
|  |  |
|  |  +--AdminController.php <- Heres where I want to get my parameter
|  |
|  +--DependencyInjection
|  +--Entity
|  +--Resources
|     |
|     +--config
|        |
|        +--custom.yaml <- There are my custom params
|        +--services.yaml <- Heres where I should register my controller as service?
|
+--assets
|
+--bin
|
+--config
|
+--public
|
+--src
|
+--templates
|
+--vendor <- Heres my admin bundle as symlink

The AdminBundle folder is installer via composer as symlink so I can use it in my project, so knowing this, anyone know how can I inject ParametersBag or the parameter directly into my controller? Im so so confused, the docs can't help me so I really need your help.


Viewing all articles
Browse latest Browse all 3924


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>