SlideShare a Scribd company logo
Bài 5
Hướng dẫn xây dựng Extension
Nhắc lại bài cũ
• Chỉnh sửa template thông qua chỉnh sửa hình ảnh, chỉnh
sửa CSS
• Cấu trúc file và thư mục của một Template
Bài 5 - Hướng dẫn xây dựng Extension
Mục tiêu bài học
• Hiểu rõ cấu trúc của component; module
• Hiểu rõ về quy trình, cách thức, giải pháp xây dựng
component, module
Bài 5 - Hướng dẫn xây dựng Extension
Xây dựng Component
Xây dựng component theo mô hình MVC
- Các component Joomla được xây dựng theo mô hình MVC
(Model-View-Controler);
User
(Khách truy
cập web)
Bài 5 - Hướng dẫn xây dựng Extension
View
(tạo giao diện hiển
thị)
Model
(thiết lập các
chức năng web)
Controler
(điều khiển, xử lý
tương tác)
Xây dựng Component
Xây dựng 1 Component đơn giản: Component Hello
Bài 5 - Hướng dẫn xây dựng Extension
Xây dựng Component
Component cơ bản có 5 file:
• site/hello.php - file tạo entry point
• site/controller.php - Thiết lập điều khiển
• site/views/hello/view.html.php - Thiết lập
hiển thị
• site/views/hello/tmpl/default.php - Tạo giao
diện hiển thị
• hello.xml - Đóng gói thành bộ cài
Bài 5 - Hướng dẫn xây dựng Extension
• site/hello.php - file tạo entry point
• site/controller.php - Thiết lập điều khiển
• site/views/hello/view.html.php - Thiết lập
hiển thị
• site/views/hello/tmpl/default.php - Tạo giao
diện hiển thị
• hello.xml - Đóng gói thành bộ cài
Xây dựng Component
Lập trình file Hello.php - Tạo entry point
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JPATH_COMPONENT.DS.'controller.php' );
if ($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
$classname = 'HelloController'.$controller;
$controller = new $classname();
$controller->execute( JRequest::getVar( 'task' ) );
$controller->redirect();
Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( JPATH_COMPONENT.DS.'controller.php' );
if ($controller = JRequest::getWord('controller')) {
$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';
if (file_exists($path)) {
require_once $path;
} else {
$controller = '';
}
}
$classname = 'HelloController'.$controller;
$controller = new $classname();
$controller->execute( JRequest::getVar( 'task' ) );
$controller->redirect();
Xây dựng Component
Tạo controller với file controller.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class HelloController extends JController
{
function display()
{
parent::display();
}
}
Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.controller');
class HelloController extends JController
{
function display()
{
parent::display();
}
}
Xây dựng Component
Tạo view - lập trình file site/views/hello/view.html.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class HelloViewHello extends JView
{
function display($tpl = null)
{
$greeting = "Hello, World!";
$this->assignRef( 'greeting', $greeting );
parent::display($tpl);
}
}
Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class HelloViewHello extends JView
{
function display($tpl = null)
{
$greeting = "Hello, World!";
$this->assignRef( 'greeting', $greeting );
parent::display($tpl);
}
}
Xây dựng Component
Tạo Template tại file site/views/hello/tmpl/default.php
<?php defined('_JEXEC') or die('Restricted access'); ?>
<h1><?php echo $this->greeting; ?></h1>
Bài 5 - Hướng dẫn xây dựng Extension
Xây dựng Component
Viết file XML (install.xml)
<?xml version="1.0" encoding="utf-8"?>
<install type="component" version="1.5.0">
<name>Hello</name>
<creationDate>2007-02-22</creationDate>
<author>John Doe</author>
<authorEmail>john.doe@example.org</authorEmail>
<authorUrl>http://www.example.org</authorUrl>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<version>1.01</version>
<description>Description of the component ...</description>
<files folder="site">
<filename>controller.php</filename>
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>views/index.html</filename>
<filename>views/hello/index.html</filename>
<filename>views/hello/view.html.php</filename>
<filename>views/hello/tmpl/default.php</filename>
<filename>views/hello/tmpl/index.html</filename>
</files>
Bài 5 - Hướng dẫn xây dựng Extension
<?xml version="1.0" encoding="utf-8"?>
<install type="component" version="1.5.0">
<name>Hello</name>
<creationDate>2007-02-22</creationDate>
<author>John Doe</author>
<authorEmail>john.doe@example.org</authorEmail>
<authorUrl>http://www.example.org</authorUrl>
<copyright>Copyright Info</copyright>
<license>License Info</license>
<version>1.01</version>
<description>Description of the component ...</description>
<files folder="site">
<filename>controller.php</filename>
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>views/index.html</filename>
<filename>views/hello/index.html</filename>
<filename>views/hello/view.html.php</filename>
<filename>views/hello/tmpl/default.php</filename>
<filename>views/hello/tmpl/index.html</filename>
</files>
Xây dựng Component
<administration>
<menu>Hello World!</menu>
<files folder="admin">
<filename>hello.php</filename>
<filename>index.html</filename>
</files>
</administration>
</install>
Bài 5 - Hướng dẫn xây dựng Extension
<administration>
<menu>Hello World!</menu>
<files folder="admin">
<filename>hello.php</filename>
<filename>index.html</filename>
</files>
</administration>
</install>
Xây dựng Component
Tạo file index.html để bảo mật
<html><body bgcolor="#FFFFFF"></body></html>
Bài 5 - Hướng dẫn xây dựng Extension
Xây dựng Component
Bổ xung Model tại site/models/hello.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
class HelloModelHello extends JModel
{
function getGreeting()
{
return 'Hello, World!';
}
}Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.model' );
class HelloModelHello extends JModel
{
function getGreeting()
{
return 'Hello, World!';
}
}
Xây dựng Component
Sử dụng Model: bằng cách thay đổi tại dòng $greeting =
"Hello World!"; tại file site/views/hello/view.html.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class HelloViewHello extends JView
{
function display($tpl = null)
{
$model =& $this->getModel();
$greeting = $model->getGreeting();
$this->assignRef( 'greeting', $greeting );
parent::display($tpl);
}
}Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.application.component.view');
class HelloViewHello extends JView
{
function display($tpl = null)
{
$model =& $this->getModel();
$greeting = $model->getGreeting();
$this->assignRef( 'greeting', $greeting );
parent::display($tpl);
}
}
Xây dựng Component
Bổ sung file vào gói cài đặt bằng dòng lệnh
<filename>models/hello.php</filename>
<files folder="site">
<filename>controller.php</filename>
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>models/hello.php</filename>
<filename>models/index.html</filename>
<filename>views/index.html</filename>
<filename>views/hello/index.html</filename>
<filename>views/hello/view.html.php</filename>
<filename>views/hello/tmpl/default.php</filename>
<filename>views/hello/tmpl/index.html</filename>
</files>
Bài 5 - Hướng dẫn xây dựng Extension
<files folder="site">
<filename>controller.php</filename>
<filename>hello.php</filename>
<filename>index.html</filename>
<filename>models/hello.php</filename>
<filename>models/index.html</filename>
<filename>views/index.html</filename>
<filename>views/hello/index.html</filename>
<filename>views/hello/view.html.php</filename>
<filename>views/hello/tmpl/default.php</filename>
<filename>views/hello/tmpl/index.html</filename>
</files>
Xây dựng Module
Cấu trúc các file trong 1 module:
• mod_helloworld.php
• mod_helloworld.xml
• helper.php
• tmpl/default.php
Bài 5 - Hướng dẫn xây dựng Extension
• mod_helloworld.php
• mod_helloworld.xml
• helper.php
• tmpl/default.php
Xây dựng Module
File mod_helloworld.php
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( dirname(__FILE__).DS.'helper.php' );
$hello = modHelloWorldHelper::getHello( $params );
require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );
?>
Bài 5 - Hướng dẫn xây dựng Extension
<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
require_once( dirname(__FILE__).DS.'helper.php' );
$hello = modHelloWorldHelper::getHello( $params );
require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) );
?>
Xây dựng Module
File helper.php
<?php
class modHelloWorldHelper
{
function getHello( $params )
{
return 'Hello, World!';
}
}
?>
Bài 5 - Hướng dẫn xây dựng Extension
<?php
class modHelloWorldHelper
{
function getHello( $params )
{
return 'Hello, World!';
}
}
?>
Xây dựng Module
File tmpl/defalt.php
<?php // no direct access
defined( '_JEXEC' ) or die( 'Restricted access' ); ?>
<?php echo $hello; ?>
Bài 5 - Hướng dẫn xây dựng Extension
Xây dựng Module
File mod_hello_world.xml
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<name>Hello, World!</name>
<author>John Doe</author>
<version>1.5.0</version>
<description>A simple Hello, World! module.</description>
<files>
<filename>mod_helloworld.xml</filename>
<filename module="mod_helloworld">mod_helloworld.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<params>
</params>
</install>
Bài 5 - Hướng dẫn xây dựng Extension
<?xml version="1.0" encoding="utf-8"?>
<install type="module" version="1.5.0">
<name>Hello, World!</name>
<author>John Doe</author>
<version>1.5.0</version>
<description>A simple Hello, World! module.</description>
<files>
<filename>mod_helloworld.xml</filename>
<filename module="mod_helloworld">mod_helloworld.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
</files>
<params>
</params>
</install>
Xây dựng Module
Tạo file index.html trong các thư mục của module để
bảo mật với nội dung:
<html><body bgcolor="#FFFFFF"></body></html>
Bài 5 - Hướng dẫn xây dựng Extension
Tổng kết bài học
• Các component trong Joomla được xây dựng theo mô
hình MVC và dựa vào Joomla Framework - thư viện mã
nguồn sẵn có trong Joomla CMS.
• Quy trình xây dựng giống nhau đối với tất cả các
component hay module.
• Sau khi hoàn thiện lập trình một component hay module,
cần đóng gói thành file .zip để có thể cài đặt vào Joomla
từ trình cài đặt tháo gỡ tự động của Joomla
• Các component trong Joomla được xây dựng theo mô
hình MVC và dựa vào Joomla Framework - thư viện mã
nguồn sẵn có trong Joomla CMS.
• Quy trình xây dựng giống nhau đối với tất cả các
component hay module.
• Sau khi hoàn thiện lập trình một component hay module,
cần đóng gói thành file .zip để có thể cài đặt vào Joomla
từ trình cài đặt tháo gỡ tự động của Joomla
Bài 5 - Hướng dẫn xây dựng Extension

More Related Content

PDF
Web301 slide 2
PDF
Bài 4 Bảo mật cho website - Xây dựng ứng dụng web
PDF
Web301 slide 4
PDF
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
DOCX
Hướng dẫn xây dựng ứng dụng web theo mô hình MVC bằng ngôn ngữ Java
PDF
Bài 6 Lập trình PHP (phần 4) Làm việc với cookie và session - Giáo trình FPT
PDF
Web301 slide 1
PDF
Bài 2 Các kỹ thuật lập trình MySQL với PHP nâng cao - Xây dựng ứng dụng web
Web301 slide 2
Bài 4 Bảo mật cho website - Xây dựng ứng dụng web
Web301 slide 4
Bài 1 Lập trình website theo mô hình MVC - Xây dựng ứng dụng web
Hướng dẫn xây dựng ứng dụng web theo mô hình MVC bằng ngôn ngữ Java
Bài 6 Lập trình PHP (phần 4) Làm việc với cookie và session - Giáo trình FPT
Web301 slide 1
Bài 2 Các kỹ thuật lập trình MySQL với PHP nâng cao - Xây dựng ứng dụng web

What's hot (20)

PPTX
The First 2015 Saigon WordPress Meetup
DOCX
Tài liệu Zend Framework 2 - Cài đặt và cấu hình Zend Framework 2 - Bài 2
PDF
Bài 3 Lập trình PHP (phần 1) - Giáo trình FPT
PDF
Web201 slide 1
PDF
Web3012 slide 8
PPTX
Wp hoi-thao-phan-quyen
PDF
Bài 7 Xây dựng website sử dụng PHP và MySQL - Giáo trình FPT
PDF
Web201 slide 6
PPTX
Mysql Workbench hướng dẫn cài đặt - Video tiếng Việt
PPTX
Giáo trình lập trình Wordpress - bài 4 - Tạo Plugin căn bản
PDF
Web201 slide 7
PDF
tao module joomla 1.5
PDF
Zend Framework 2 - Thao tác Database trong Zend Framework 2 - Bài 8
PPTX
Tài liệu lập trình Wordpress - bài 5 - Action và Action hook trong Wordpress
PDF
Web3012 assignment
PDF
Tài liệu Zend Framework 2 : Thêm dữ liệu vào database trong ZF2 - Bài 10
PPTX
Học lập trình Wordpress - bài 2 - Tìm hiểu cấu trúc và cấu hình nâng cao
DOCX
Học Zend Framework - Khóa học lập trình Zend Framework
PDF
Giáo trình Zend Framework 2.0 - Nhúng template vào ứng dung ZF2 (P3) - Bài 7
PDF
Web201 slide 2
The First 2015 Saigon WordPress Meetup
Tài liệu Zend Framework 2 - Cài đặt và cấu hình Zend Framework 2 - Bài 2
Bài 3 Lập trình PHP (phần 1) - Giáo trình FPT
Web201 slide 1
Web3012 slide 8
Wp hoi-thao-phan-quyen
Bài 7 Xây dựng website sử dụng PHP và MySQL - Giáo trình FPT
Web201 slide 6
Mysql Workbench hướng dẫn cài đặt - Video tiếng Việt
Giáo trình lập trình Wordpress - bài 4 - Tạo Plugin căn bản
Web201 slide 7
tao module joomla 1.5
Zend Framework 2 - Thao tác Database trong Zend Framework 2 - Bài 8
Tài liệu lập trình Wordpress - bài 5 - Action và Action hook trong Wordpress
Web3012 assignment
Tài liệu Zend Framework 2 : Thêm dữ liệu vào database trong ZF2 - Bài 10
Học lập trình Wordpress - bài 2 - Tìm hiểu cấu trúc và cấu hình nâng cao
Học Zend Framework - Khóa học lập trình Zend Framework
Giáo trình Zend Framework 2.0 - Nhúng template vào ứng dung ZF2 (P3) - Bài 7
Web201 slide 2
Ad

Viewers also liked (9)

PDF
Bài 7: Xác thực và quản lý tài khoản - Giáo trình FPT
PDF
Bài 5: Quản trị một mạng an toàn và Bảo mật các mạng không dây - Giáo trình FPT
PDF
Chương 6 Bảo mật - Giáo trình FPT
PDF
Bài 4: Bảo mật máy chủ, ứng dụng, dữ liệu và mạng - Giáo trình FPT
PDF
Bài 2: Phần mềm độc hại và các dạng tấn công sử dụng kỹ nghệ xã hội - Giáo tr...
PDF
Bài 3: Tấn công vào ứng dụng và mạng, đánh giá khả năng thiệt hại và làm giảm...
PDF
Chương 5 Chia sẻ file và máy in trên mạng - Giáo trình FPT
PDF
Bài 8: Triển khai bảo mật sử dụng chính sách nhóm (Group policy) - Giáo trình...
PDF
Bài 1: GIỚI THIỆU VỀ BẢO MẬT - Giáo trình FPT
Bài 7: Xác thực và quản lý tài khoản - Giáo trình FPT
Bài 5: Quản trị một mạng an toàn và Bảo mật các mạng không dây - Giáo trình FPT
Chương 6 Bảo mật - Giáo trình FPT
Bài 4: Bảo mật máy chủ, ứng dụng, dữ liệu và mạng - Giáo trình FPT
Bài 2: Phần mềm độc hại và các dạng tấn công sử dụng kỹ nghệ xã hội - Giáo tr...
Bài 3: Tấn công vào ứng dụng và mạng, đánh giá khả năng thiệt hại và làm giảm...
Chương 5 Chia sẻ file và máy in trên mạng - Giáo trình FPT
Bài 8: Triển khai bảo mật sử dụng chính sách nhóm (Group policy) - Giáo trình...
Bài 1: GIỚI THIỆU VỀ BẢO MẬT - Giáo trình FPT
Ad

Similar to Web203 slide 5 (20)

PDF
Chater 1
PPT
Joomla CMS framework (1.6 - Old version)
PDF
Lap trinh-joomla-15-theo-mo-hinh-mvc
PDF
Web203 slide 3
PDF
Bài 3 Cài đặt và quản lý các Extension của Joomla
PDF
Bai tap lap trinh web voi joomla csau
PPT
Tìm hiểu về Joomla
PDF
PDF
Tailieuonline.tk joomla-viet-component
PDF
Cloud2s huong.dan.su.dung.joomla.v1.5
DOC
Tutoria mvc framework
PDF
Huong dan su dung joomla 1.5
PDF
Hỏi tình hình bk tiny bktiny-hdsd
PPT
11 building joomla! extensions with flex integration
PDF
Báo cáo thực tập athena nguyễn anh tuấn
DOC
LinQ to XML
PDF
Căn bản về xml
PDF
Báo cáo tiến độ thực tập hàng tuần tại trung tâm athena tuan 1
PPT
Php05 xay dungungdung
DOCX
Gioi thieu joomla
Chater 1
Joomla CMS framework (1.6 - Old version)
Lap trinh-joomla-15-theo-mo-hinh-mvc
Web203 slide 3
Bài 3 Cài đặt và quản lý các Extension của Joomla
Bai tap lap trinh web voi joomla csau
Tìm hiểu về Joomla
Tailieuonline.tk joomla-viet-component
Cloud2s huong.dan.su.dung.joomla.v1.5
Tutoria mvc framework
Huong dan su dung joomla 1.5
Hỏi tình hình bk tiny bktiny-hdsd
11 building joomla! extensions with flex integration
Báo cáo thực tập athena nguyễn anh tuấn
LinQ to XML
Căn bản về xml
Báo cáo tiến độ thực tập hàng tuần tại trung tâm athena tuan 1
Php05 xay dungungdung
Gioi thieu joomla

More from tuanduongcntt (20)

PDF
Slide5 html5
PDF
Slide4 html5
PDF
Slide3 html5
PDF
Slide2 html5
PDF
Slide1 html5
PDF
Slide6 html5
PDF
Web301 slide 7
PDF
Web301 slide 6
PDF
Web301 slide 5
PDF
Web301 slide 3
PDF
Web2032 assignment
PDF
Web203 slide 9
PDF
Web203 slide 8
PDF
Web203 slide 7
PDF
Web203 slide 4
PDF
Web203 slide 2
PDF
Web203 slide 1
PDF
Web2032 slide 10
PDF
Web2022 slide 7
PDF
Web2022 slide 6
Slide5 html5
Slide4 html5
Slide3 html5
Slide2 html5
Slide1 html5
Slide6 html5
Web301 slide 7
Web301 slide 6
Web301 slide 5
Web301 slide 3
Web2032 assignment
Web203 slide 9
Web203 slide 8
Web203 slide 7
Web203 slide 4
Web203 slide 2
Web203 slide 1
Web2032 slide 10
Web2022 slide 7
Web2022 slide 6

Web203 slide 5

  • 1. Bài 5 Hướng dẫn xây dựng Extension
  • 2. Nhắc lại bài cũ • Chỉnh sửa template thông qua chỉnh sửa hình ảnh, chỉnh sửa CSS • Cấu trúc file và thư mục của một Template Bài 5 - Hướng dẫn xây dựng Extension
  • 3. Mục tiêu bài học • Hiểu rõ cấu trúc của component; module • Hiểu rõ về quy trình, cách thức, giải pháp xây dựng component, module Bài 5 - Hướng dẫn xây dựng Extension
  • 4. Xây dựng Component Xây dựng component theo mô hình MVC - Các component Joomla được xây dựng theo mô hình MVC (Model-View-Controler); User (Khách truy cập web) Bài 5 - Hướng dẫn xây dựng Extension View (tạo giao diện hiển thị) Model (thiết lập các chức năng web) Controler (điều khiển, xử lý tương tác)
  • 5. Xây dựng Component Xây dựng 1 Component đơn giản: Component Hello Bài 5 - Hướng dẫn xây dựng Extension
  • 6. Xây dựng Component Component cơ bản có 5 file: • site/hello.php - file tạo entry point • site/controller.php - Thiết lập điều khiển • site/views/hello/view.html.php - Thiết lập hiển thị • site/views/hello/tmpl/default.php - Tạo giao diện hiển thị • hello.xml - Đóng gói thành bộ cài Bài 5 - Hướng dẫn xây dựng Extension • site/hello.php - file tạo entry point • site/controller.php - Thiết lập điều khiển • site/views/hello/view.html.php - Thiết lập hiển thị • site/views/hello/tmpl/default.php - Tạo giao diện hiển thị • hello.xml - Đóng gói thành bộ cài
  • 7. Xây dựng Component Lập trình file Hello.php - Tạo entry point <?php defined( '_JEXEC' ) or die( 'Restricted access' ); require_once( JPATH_COMPONENT.DS.'controller.php' ); if ($controller = JRequest::getWord('controller')) { $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php'; if (file_exists($path)) { require_once $path; } else { $controller = ''; } } $classname = 'HelloController'.$controller; $controller = new $classname(); $controller->execute( JRequest::getVar( 'task' ) ); $controller->redirect(); Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); require_once( JPATH_COMPONENT.DS.'controller.php' ); if ($controller = JRequest::getWord('controller')) { $path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php'; if (file_exists($path)) { require_once $path; } else { $controller = ''; } } $classname = 'HelloController'.$controller; $controller = new $classname(); $controller->execute( JRequest::getVar( 'task' ) ); $controller->redirect();
  • 8. Xây dựng Component Tạo controller với file controller.php <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.application.component.controller'); class HelloController extends JController { function display() { parent::display(); } } Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport('joomla.application.component.controller'); class HelloController extends JController { function display() { parent::display(); } }
  • 9. Xây dựng Component Tạo view - lập trình file site/views/hello/view.html.php <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); class HelloViewHello extends JView { function display($tpl = null) { $greeting = "Hello, World!"; $this->assignRef( 'greeting', $greeting ); parent::display($tpl); } } Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); class HelloViewHello extends JView { function display($tpl = null) { $greeting = "Hello, World!"; $this->assignRef( 'greeting', $greeting ); parent::display($tpl); } }
  • 10. Xây dựng Component Tạo Template tại file site/views/hello/tmpl/default.php <?php defined('_JEXEC') or die('Restricted access'); ?> <h1><?php echo $this->greeting; ?></h1> Bài 5 - Hướng dẫn xây dựng Extension
  • 11. Xây dựng Component Viết file XML (install.xml) <?xml version="1.0" encoding="utf-8"?> <install type="component" version="1.5.0"> <name>Hello</name> <creationDate>2007-02-22</creationDate> <author>John Doe</author> <authorEmail>john.doe@example.org</authorEmail> <authorUrl>http://www.example.org</authorUrl> <copyright>Copyright Info</copyright> <license>License Info</license> <version>1.01</version> <description>Description of the component ...</description> <files folder="site"> <filename>controller.php</filename> <filename>hello.php</filename> <filename>index.html</filename> <filename>views/index.html</filename> <filename>views/hello/index.html</filename> <filename>views/hello/view.html.php</filename> <filename>views/hello/tmpl/default.php</filename> <filename>views/hello/tmpl/index.html</filename> </files> Bài 5 - Hướng dẫn xây dựng Extension <?xml version="1.0" encoding="utf-8"?> <install type="component" version="1.5.0"> <name>Hello</name> <creationDate>2007-02-22</creationDate> <author>John Doe</author> <authorEmail>john.doe@example.org</authorEmail> <authorUrl>http://www.example.org</authorUrl> <copyright>Copyright Info</copyright> <license>License Info</license> <version>1.01</version> <description>Description of the component ...</description> <files folder="site"> <filename>controller.php</filename> <filename>hello.php</filename> <filename>index.html</filename> <filename>views/index.html</filename> <filename>views/hello/index.html</filename> <filename>views/hello/view.html.php</filename> <filename>views/hello/tmpl/default.php</filename> <filename>views/hello/tmpl/index.html</filename> </files>
  • 12. Xây dựng Component <administration> <menu>Hello World!</menu> <files folder="admin"> <filename>hello.php</filename> <filename>index.html</filename> </files> </administration> </install> Bài 5 - Hướng dẫn xây dựng Extension <administration> <menu>Hello World!</menu> <files folder="admin"> <filename>hello.php</filename> <filename>index.html</filename> </files> </administration> </install>
  • 13. Xây dựng Component Tạo file index.html để bảo mật <html><body bgcolor="#FFFFFF"></body></html> Bài 5 - Hướng dẫn xây dựng Extension
  • 14. Xây dựng Component Bổ xung Model tại site/models/hello.php <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.model' ); class HelloModelHello extends JModel { function getGreeting() { return 'Hello, World!'; } }Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.model' ); class HelloModelHello extends JModel { function getGreeting() { return 'Hello, World!'; } }
  • 15. Xây dựng Component Sử dụng Model: bằng cách thay đổi tại dòng $greeting = "Hello World!"; tại file site/views/hello/view.html.php <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); class HelloViewHello extends JView { function display($tpl = null) { $model =& $this->getModel(); $greeting = $model->getGreeting(); $this->assignRef( 'greeting', $greeting ); parent::display($tpl); } }Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); jimport( 'joomla.application.component.view'); class HelloViewHello extends JView { function display($tpl = null) { $model =& $this->getModel(); $greeting = $model->getGreeting(); $this->assignRef( 'greeting', $greeting ); parent::display($tpl); } }
  • 16. Xây dựng Component Bổ sung file vào gói cài đặt bằng dòng lệnh <filename>models/hello.php</filename> <files folder="site"> <filename>controller.php</filename> <filename>hello.php</filename> <filename>index.html</filename> <filename>models/hello.php</filename> <filename>models/index.html</filename> <filename>views/index.html</filename> <filename>views/hello/index.html</filename> <filename>views/hello/view.html.php</filename> <filename>views/hello/tmpl/default.php</filename> <filename>views/hello/tmpl/index.html</filename> </files> Bài 5 - Hướng dẫn xây dựng Extension <files folder="site"> <filename>controller.php</filename> <filename>hello.php</filename> <filename>index.html</filename> <filename>models/hello.php</filename> <filename>models/index.html</filename> <filename>views/index.html</filename> <filename>views/hello/index.html</filename> <filename>views/hello/view.html.php</filename> <filename>views/hello/tmpl/default.php</filename> <filename>views/hello/tmpl/index.html</filename> </files>
  • 17. Xây dựng Module Cấu trúc các file trong 1 module: • mod_helloworld.php • mod_helloworld.xml • helper.php • tmpl/default.php Bài 5 - Hướng dẫn xây dựng Extension • mod_helloworld.php • mod_helloworld.xml • helper.php • tmpl/default.php
  • 18. Xây dựng Module File mod_helloworld.php <?php defined( '_JEXEC' ) or die( 'Restricted access' ); require_once( dirname(__FILE__).DS.'helper.php' ); $hello = modHelloWorldHelper::getHello( $params ); require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) ); ?> Bài 5 - Hướng dẫn xây dựng Extension <?php defined( '_JEXEC' ) or die( 'Restricted access' ); require_once( dirname(__FILE__).DS.'helper.php' ); $hello = modHelloWorldHelper::getHello( $params ); require( JModuleHelper::getLayoutPath( 'mod_helloworld' ) ); ?>
  • 19. Xây dựng Module File helper.php <?php class modHelloWorldHelper { function getHello( $params ) { return 'Hello, World!'; } } ?> Bài 5 - Hướng dẫn xây dựng Extension <?php class modHelloWorldHelper { function getHello( $params ) { return 'Hello, World!'; } } ?>
  • 20. Xây dựng Module File tmpl/defalt.php <?php // no direct access defined( '_JEXEC' ) or die( 'Restricted access' ); ?> <?php echo $hello; ?> Bài 5 - Hướng dẫn xây dựng Extension
  • 21. Xây dựng Module File mod_hello_world.xml <?xml version="1.0" encoding="utf-8"?> <install type="module" version="1.5.0"> <name>Hello, World!</name> <author>John Doe</author> <version>1.5.0</version> <description>A simple Hello, World! module.</description> <files> <filename>mod_helloworld.xml</filename> <filename module="mod_helloworld">mod_helloworld.php</filename> <filename>index.html</filename> <filename>helper.php</filename> <filename>tmpl/default.php</filename> <filename>tmpl/index.html</filename> </files> <params> </params> </install> Bài 5 - Hướng dẫn xây dựng Extension <?xml version="1.0" encoding="utf-8"?> <install type="module" version="1.5.0"> <name>Hello, World!</name> <author>John Doe</author> <version>1.5.0</version> <description>A simple Hello, World! module.</description> <files> <filename>mod_helloworld.xml</filename> <filename module="mod_helloworld">mod_helloworld.php</filename> <filename>index.html</filename> <filename>helper.php</filename> <filename>tmpl/default.php</filename> <filename>tmpl/index.html</filename> </files> <params> </params> </install>
  • 22. Xây dựng Module Tạo file index.html trong các thư mục của module để bảo mật với nội dung: <html><body bgcolor="#FFFFFF"></body></html> Bài 5 - Hướng dẫn xây dựng Extension
  • 23. Tổng kết bài học • Các component trong Joomla được xây dựng theo mô hình MVC và dựa vào Joomla Framework - thư viện mã nguồn sẵn có trong Joomla CMS. • Quy trình xây dựng giống nhau đối với tất cả các component hay module. • Sau khi hoàn thiện lập trình một component hay module, cần đóng gói thành file .zip để có thể cài đặt vào Joomla từ trình cài đặt tháo gỡ tự động của Joomla • Các component trong Joomla được xây dựng theo mô hình MVC và dựa vào Joomla Framework - thư viện mã nguồn sẵn có trong Joomla CMS. • Quy trình xây dựng giống nhau đối với tất cả các component hay module. • Sau khi hoàn thiện lập trình một component hay module, cần đóng gói thành file .zip để có thể cài đặt vào Joomla từ trình cài đặt tháo gỡ tự động của Joomla Bài 5 - Hướng dẫn xây dựng Extension