ขั้นตอนที่ 2 สร้าง Component สำหรับ Joomla 2.5 การสร้างส่วน view
ขั้นตอนที่ 3 สร้าง Component สำหรับ Joomla 2.5 การเพิ่มเมนูในหน้าเว็บ
ตอนนี้เราจะเพิ่มส่วนของ model เข้ามาใน component ด้วย เข้าไปในโฟลเดอร์
helloworld -> site สร้างโฟลเดอร์ models แล้วเข้าไปสร้างไฟล์ helloworld.php ใส่โค้ด
โค้ด: เลือกทั้งหมด
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla modelitem library
jimport('joomla.application.component.modelitem');
/**
* HelloWorld Model
*/
class HelloWorldModelHelloWorld extends JModelItem
{
/**
* @var string msg
*/
protected $msg;
/**
* Get the message
* @return string The message to be displayed to the user
*/
public function getMsg()
{
if (!isset($this->msg))
{
$this->msg = 'Hello World in Model';
}
return $this->msg;
}
}
?>
โค้ด: เลือกทั้งหมด
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* HTML View class for the HelloWorld Component
*/
class HelloWorldViewHelloWorld extends JView
{
// Overwriting JView display method
function display($tpl = null)
{
// Assign data to the view
$this->msg = $this->get('Msg');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Display the view
parent::display($tpl);
}
}
?>
โค้ด: เลือกทั้งหมด
<version>0.0.3</version>
โค้ด: เลือกทั้งหมด
<version>0.0.4</version>
โค้ด: เลือกทั้งหมด
<files folder="site">
<filename>index.html</filename>
<filename>helloworld.php</filename>
<filename>controller.php</filename>
<folder>views</folder>
</files>
โค้ด: เลือกทั้งหมด
<files folder="site">
<filename>index.html</filename>
<filename>helloworld.php</filename>
<filename>controller.php</filename>
<folder>views</folder>
<folder>models</folder>
</files>