I don't understand it clearly. How is this related to "routing.yml" file ?eange08 เขียน: ↑05/11/2024 1:36 pm Based on the properties you've decided to use in the controller, we can adjust the `services.yml` and the `controller` to align with this setup:
### `services.yml`
In `services.yml`, specify only the `arguments` that match the properties in the controller's constructor, removing any unnecessary arguments:
```yamlโค้ด: เลือกทั้งหมด
services: mindphp.m_example.controller: class: mindphp\m_example\controller\main arguments: - '@config' - '@cache' - '@dbal.conn' - '@template' - '@user' - '@controller.helper' - '@service_container' - '@request' - '@auth' - '%core.table_prefix%'
### `controller/main.php`
Update the controller to use only the needed properties:
```phpโค้ด: เลือกทั้งหมด
<?php namespace mindphp\m_example\controller; class main { protected $config; protected $cache; protected $db; protected $template; protected $user; protected $helper; protected $phpbb_container; protected $request; protected $auth; protected $table_prefix; public function __construct(\phpbb\config\config $config, \phpbb\cache\service $cache, \phpbb\db\driver\driver_interface $db, \phpbb\template\template $template, \phpbb\user $user, \phpbb\controller\helper $helper, Container $phpbb_container, \phpbb\request\request $request, \phpbb\auth\auth $auth, $table_prefix) { $this->config = $config; $this->cache = $cache; $this->db = $db; $this->template = $template; $this->user = $user; $this->helper = $helper; $this->phpbb_container = $phpbb_container; $this->request = $request; $this->auth = $auth; $this->table_prefix = $table_prefix; } public function handle() { // Assign a greeting to the template for testing $this->template->assign_vars([ 'GREETING' => 'Hello from m_example!', ]); return $this->helper->render('m_example_template.html'); } }
### Summary
- **`services.yml`**: Only include the arguments specified in the constructor.
- **`controller/main.php`**: Keep only the properties that are actively used.
Whatever I changed in services.yml and controller/main.php, the error of routing.yml remains the same .
How is it related ?
โค้ด: เลือกทั้งหมด
m_example_main:
path: /m_example_main
defaults:
_controller: mindphp.m_example.controller:handle
โค้ด: เลือกทั้งหมด
Fatal error: Uncaught InvalidArgumentException: The definition of "m_example_main" in "C:\xampp\htdocs\phpbb_3\ext/mindphp/m_example/config/routing.yml" must be a YAML array. in C:\xampp\htdocs\phpbb_3\vendor\symfony\routing\Loader\YamlFileLoader.php:203 Stack trace: #0 C:\xampp\htdocs\phpbb_3\vendor\symfony\routing\Loader\YamlFileLoader.php(88): Symfony\Component\Routing\Loader\YamlFileLoader->validate(NULL, 'm_example_main', 'C:\\xampp\\htdocs...') #1 C:\xampp\htdocs\phpbb_3\vendor\symfony\config\Loader\DelegatingLoader.php(40): Symfony\Component\Routing\Loader\YamlFileLoader->load('ext/mindphp/m_e...', 'yaml') #2 C:\xampp\htdocs\phpbb_3\phpbb\routing\router.php(116): Symfony\Component\Config\Loader\DelegatingLoader->load('ext/mindphp/m_e...', 'yaml') #3 C:\xampp\htdocs\phpbb_3\phpbb\routing\router.php(261): phpbb\routing\router->get_routes() #4 C:\xampp\htdocs\phpbb_3\phpbb\routing\router.php(246): phpbb\routing\router->create_dumped_url_generator() #5 C:\xampp\htdocs\phpbb_3\phpbb\routing\router.php(168): phpbb\routing\router->get_generator() #6 C:\xampp\htdocs\phpbb_3\phpbb\routing\helper.php(148): phpbb\routing\router->generate('phpbb_ucp_forgo...', Array, 1) #7 C:\xampp\htdocs\phpbb_3\phpbb\controller\helper.php(212): phpbb\routing\helper->route('phpbb_ucp_forgo...', Array, true, false, 1) #8 C:\xampp\htdocs\phpbb_3\index.php(226): phpbb\controller\helper->route('phpbb_ucp_forgo...') #9 {main} thrown in C:\xampp\htdocs\phpbb_3\vendor\symfony\routing\Loader\YamlFileLoader.php on line 203