การเขียน Joomla! 1.0.x component ตอนที่ 1
แก้ไขล่าสุด ใน วันพุธที่ 24 มิถุนายน 2552 เวลา 00:41 น. เขียนโดย Prasit Gebsaap วันจันทร์ที่ 19 พฤษภาคม 2551 เวลา 22:43 น.
Joomla! component เป็นส่วนขยายของ Joomla! ที่มีการใช้พื้นที่หลักของ web site ในการแสดงผลต่างจาก modules ที่ใช้พื้นที่ที่กำหนดใน template สำหรับการแสดงผล ซึ่งเรียกว่า module position โดยใน version 1.0.x นี้การเขียน component ไม่มีความซับซ้อนมากนัก (ในแง่ของข้อกำหนดและ concept) จึงเหมาะสำหรับมือใหม่มากกว่าการเริ่มต้นกับ Joomla! 1.5.x โดยการเรียกใช้ component จะเป็นการเรียกผ่าน menu ซึ่งกำหนดโดยผู้ดแล web site เป็นหลัก โดย Joomla! core จะทำการเรียกโดยการ include ไฟล์หลักของ component ตามตัวแปรชื่อ $option เช่น index.php?option=com_mymenu จะทำการตรวจสอบไฟล์จาก folder ชื่อ components/com_mymenu และ include ไฟล์ mymenu.php
สำหรับบทความนี้จะทำให้ผู้อ่านเข้าใจขั้นตอนของการเขียน Joomla! 1.0.x component การสร้าง zip ไฟล์สำหรับการติดตั้ง การใช้งาน Joomla! database object เบื้องต้น
- โครงสร้างของ folder ทั้ง frontend และ backend
- การสร้างไฟล์ installation
- โครงสร้างของ j15_components
- การสร้าง toolbar (backend)
- โปรแกรมทางด้าน backend
โครงสร้างของ folder ทั้ง frontend และ backend
โครงของ folder และการตั้งชื่อ component ถือว่าสำคัญมากครับ โดยใน frontend เราจะมี folder ชื่อ /components อยู่แล้ว หาก component ของเราชื่อ mycomponent ดังนั้นเราจะใส่ไฟล์ frontend ไว้ที่ /components/com_mycomponent/ โดยเราจะมีไฟล์อยู่สามไฟล์หลักๆ ในนี้คือ/components/com_mycomponent/mycomponent.php
/components/com_mycomponent/mycomponent.html.php
/components/com_mycomponent/mycomponent.class.php
โดยในไฟล์แรก ถือว่าเป็นไฟล์บังคับเพราะเป็นไฟล์ที่ core จะหาจาก $option และ include เข้าไป สำหรับไฟล์ที่สอง เรียกว่า front_html เป็นไฟล์ที่จะมี HTML สำหรับการแสดงผลโดยเฉพาะ ส่วนไฟล์ที่สามเรียกว่า class เป็นส่วนของ Business Logic หรือ Model ตาม concept ของ Model-View-Controller (MVC) โดยเราสามารถอ้างถึงไฟล์สองไฟล์ได้โดยอาศัย method ของ $mainframe object ซึ่งเป็นตัวแปร global ที่สร้างโดย core นะครับ ดังนี้
- require ( $mainframe->getPath('front_html') );//absolute path to mycomponent.html.php
- require ( $mainframe->getPath('class') ); //absolute path to mycomponent.class.php
/administrator/components/com_mycomponent/admin.mycomponent.php
/administrator/components/com_mycomponent/admin.mycomponent.html.php
/administrator/components/com_mycomponent/toolbar.mycomponent.php
/administrator/components/com_mycomponent/toolbar.mycomponent.html.php
โดยใน folder /administrator/components/com_mycomponent นี้ก็คล้ายกับ frontend ครับแต่จะมีไฟล์สำหรับการสร้าง TOOLBAR เพิ่มเข้ามา
| < ย้อนกลับ | ถัดไป > |
|---|

