ไฟล์ main.php ซึ่งเป็นไฟล์หลักของการทำงาน
ไฟล์ routing.yml เป็นไฟล์ที่ใช้เป็นเส้นทาง
ไฟล์ services.yml เป็นไฟล์ที่ส่งค่าไปยัง ไฟล์ main.php
โดยเมื่อได้ทดสอบไฟล์พบว่า มี error เกิดขึ้น ดังภาพ
โดย error ที่าเกิดขึ้นได้ระบุว่า
โค้ด: เลือกทั้งหมด
ไม่มีการระบุ service "mindphp.sample1.controller" ใน ./config/services.yml.
ไฟล์ services.yml
โค้ด: เลือกทั้งหมด
services :
mindphp.sample1.controller:
class : mindphp\sample1\controller\main //เรียก class
argumemts: //ระบุตัวแปรที่ต้องการจะใช้
- @config
- @template
- @user
- @controller.helper
- %core.root_path%
- %core.php_ext%
โค้ด: เลือกทั้งหมด
sample1_controller:
pattern: /sample1/{name}
defaults: { __controller: mindphp.sample1.controller :base , page: 1 } กำหนดเส้นทางที่จะเรียกใช้งาน
โค้ด: เลือกทั้งหมด
<?php
namespace mindphp\sample1\controller;
class main
{
public function _construct(\phpbb\config\config $config,
\phpbb\template\template $template,
\phpbb\user $user,
\phpbb\controller\helper $helper,
$root_path, $php_ext) //เรียกใช้งาน construct
{
$this->template = $template;
$this->config = $config;
$this->user = $user;
$this->helper = $helper;
$this->root_path = $root_path;
$this->php_ext = $php_ext;
} กำหนดตัวแปร
function base ($page = 1)
{
return $this->helper->render('sample1.html'); //เรียกใช้งาน template
}
}