- 1.สร้างฟังก์ชันที่ต้องการขึ้นมา ในไฟล์ที่อยู่ในโฟลเดอร์ model ดังตัวอย่าง
2.ไปสร้างตัวแปรในไฟล์ view.html.php ที่อยู่ในโฟลเดอร์ view ดังตัวอย่าง
Code: Select all
public function getTest() { $db = JFactory::getDbo(); $query = $db->getQuery(true) ->select('*') ->from('#__place'); $db->setQuery($query); $show = $db->loadAssocList(); return $show; }
โดย $this->test ก็คือตัวแปรที่สามารถเอาไปใช้ในไฟล์ default.php ที่อยู่ในโฟลเดอร์ view ได้Code: Select all
$this->test= $this->get('Test');
โดย get('Test') ก็คือการอ้างไปหาฟังก์ชันที่ชื่อว่า getTest ที่อยู่ในไฟล์ที่อยู่ในโฟลเดอร์ model
3.วิธีการนำไปใช้ในไฟล์ default.php โดยสามารถปริ้นค่าออกมาดูรูปแบบของข้อมูลได้จากตัวแปร ดังตัวอย่างโดยผลลัพธ์จะออกมาเป็น Array ดังรูปCode: Select all
print_r($this->test); //หรือ echo ได้ echo $this->test;
วิธีการเรียกใช้ function ที่อยู่ใน model ในส่วน view ใน Joomla
Moderators: mindphp, ผู้ดูแลกระดาน
-
- PHP VIP Members
- Posts: 4859
- Joined: 08/01/2018 10:03 am
วิธีการเรียกใช้ function ที่อยู่ใน model ในส่วน view ใน Joomla
วิธีการเรียกใช้ function ที่อยู่ใน model ในส่วน view ใน Joomla มีวิธีการดังนี้
Live Simply, Laugh Often, Love Deeply.....
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Joomla Framework- MVC ทำให้ View หนึ่ง View สามารถเรียกใช้งาน Model ได้หลายโมเดล
by mindphp » 20/04/2012 1:53 pm » in Share Knowledge - 0 Replies
- 1823 Views
-
Last post by mindphp
20/04/2012 1:53 pm
-
-
-
Artificial Intelligence - M[MODEL]C[CONTROLLER]V[VIEW] [NET]NETWORKING
by chornma » 08/04/2017 4:21 pm » in SQL - Database - 1 Replies
- 737 Views
-
Last post by mindphp
13/04/2017 9:12 pm
-
-
- 0 Replies
- 1129 Views
-
Last post by mindphp
16/04/2011 5:34 am
-
-
controller เรียกใช้ function ใน model ใน JoomShopping
by Parichat » 16/06/2018 3:38 pm » in Joomla Developing Knowledge - 0 Replies
- 2010 Views
-
Last post by Parichat
16/06/2018 3:38 pm
-
-
-
สร้าง Component สำหรับ Joomla 2.5 การสร้างส่วน model
by tsukasaz » 08/05/2012 3:54 pm » in Share Knowledge - 3 Replies
- 4845 Views
-
Last post by tsukasaz
21/05/2012 1:57 pm
-
-
- 0 Replies
- 1463 Views
-
Last post by tsukasaz
07/08/2013 4:24 pm
-
-
การนำค่าที่อยู่ใน view.html.php ไปใช้ในไฟล์ default.php ใน joomla
by Parichat » 26/02/2018 3:40 pm » in Joomla Developing Knowledge - 0 Replies
- 1544 Views
-
Last post by Parichat
26/02/2018 3:40 pm
-
Who is online
Users browsing this forum: No registered users and 5 guests