สร้าง Controller คือ ส่วนจัดการข้อมูล คำนวณ ประมวลผล สั่งการทำงาน หรือ Coding หลักๆ ซึ่งการสร้าง Controller จะมีความสัมพันธ์กับการสร้างเเละกำหนด Routing ทำให้เราสามารถที่จะสร้าง Controller กี่ Controller ก็ได้ภายใน Bundle
วิธีการ Create Controller
1. สามารถที่จะ Run Command ผ่าน Netbeans ได้เลย ดังรูป
2. ให้เลือกที่คำสั่ง Command generate:controller
3. จากนั้น Command จะให้เราใส้ข้อมูลที่จะสร้าง Controller
Controller name: SitetestBundle:block
SitetestBundle ได้จาก ตอนเราสร้าง Bundle เราต้องระบุชื่อไปว่าจะใช้ของ Bundle ตัวใด จากนั้น : block คือชื่อ controller
Determine the format to use for the routing.
Routing format (php, xml, yml, annotation) [annotation]: yml
Determine the format to use for templating.
Template format (twig, php) [twig]: [Enter ได้เลย]
Instead of starting with a blank controller, you can add some actions now. An action
is a PHP function or method that executes, for example, when a given route is matched.
Actions should be suffixed by Action.
New action name (press <return> to stop adding actions): [Enter ได้เลย]
Do you confirm generation [yes]?: [Enter ได้เลย]
Generating the bundle code: OK
สำหรับคำสั่ง Commands line ให้ทำการพิมพ์คำสั่งนี้
$ php app/console generate:controller
เลือกวิธีกันได้ตามสะดวกนะทุกคน เมื่อสร้างเสร็จก็จะได้ไฟล์ ตามภาพที่แสดง
แล้วเราก็ไปกันต่อในบทต่อไปเลย