Q - How to fix yaml file error in phpBB3 custom extension ?

พูดคุย phpBB3, SMF ปัญหา การติดตั้ง ปัญหา การลง Mod การแก้ไข หน้าตาบอร์ด การใช้งาน Joomla 1.5, 1.6, 1.7, 2.5 ,3.x รวมถึง Joomla 4 การใช้งาน wordpress และ CMS อื่นๆ
การตั้งคำถาม ควรระบุรุ่นที่ใช้ ในการตั้งคำตามด้วย นะ เช่น SMF 1.1.4 หรือ SMF2.0, OpenERP, Odoo และ รายละเอียดของ server OS, php เวอร์ชั่นไหน ฐานข้อมูลอะไร

Moderator: mindphp

กฎการใช้บอร์ด
คำถามหมวดนี้ ควรระบุ รายละเอียดของ Server OS, เวอร์ชั่น ของ PHP, CMS ที่ท่านใช้
รวมถึง Hosting หรือ Control Panel Hosting
Raja Pdl
PHP VIP Members
PHP VIP Members
โพสต์: 2241
ลงทะเบียนเมื่อ: 27/05/2024 9:50 am

Re: Q - How to fix yaml file error in phpBB3 custom extension ?

โพสต์ที่ยังไม่ได้อ่าน โดย Raja Pdl »

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.
I don't understand it clearly. How is this related to "routing.yml" file ?
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
Error is

โค้ด: เลือกทั้งหมด

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
Raja Pdl
PHP VIP Members
PHP VIP Members
โพสต์: 2241
ลงทะเบียนเมื่อ: 27/05/2024 9:50 am

Re: Q - How to fix yaml file error in phpBB3 custom extension ?

โพสต์ที่ยังไม่ได้อ่าน โดย Raja Pdl »

fixed this bug by changing

in "config/routing.yml"

โค้ด: เลือกทั้งหมด

mindphp_m_example_controller:
    path:  /m_example/{action}
    defaults: {  _controller:  mindphp.m_example.controller:base , action: '' }  
in "services.yml"

โค้ด: เลือกทั้งหมด

services: 
    mindphp.m_example.controller:
        class: mindphp\m_example\controller\main
        arguments:
            - '@auth'
            - '@config'
            - "@dbal.conn"
            - '@controller.helper'
            - '@language'
            - '@pagination'
            - '@request'
            - '@template'
            - '@user'
            - '%core.root_path%'
            - '%core.php_ext%'  
            - "%core.table_prefix%"    
            - "@service_container"
   
    mindphp.m_example.listener:
        class: mindphp\m_example\event\listener
        arguments:
            - "@controller.helper"
            - "@template"
            - "@config"
            - "@user"
            - "@dbal.conn"
            - "@request"
            - "%core.php_ext%"
            - "%core.root_path%"
            - "%core.table_prefix%"          
            
        tags:
            - { name: event.listener }   

in "controller/main.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 base()
    {
        
    }
}
Thank you.
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 2