giáo trình joomla 1.5 Toàn tập

71 596 0
giáo trình joomla 1.5 Toàn tập

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Giáo trình đầy đủ thiết kế web bằng Joomla. hướng dẫn chi tiết để bạn tự tay tạo cho mình một website ưng ý mà không cần có kiến thức chuyên sâu về lập trình

Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 1 Email: vukhanh2212@gmail.com Joomla! Programming Book shopping component Chương 1: Phân tích & xây dựng hệ thống Back-End 1. Phân tích Database 2. Xây dựng cấu trúc MVC trong Back-End của Joomla 3. Đăng ký com_book trong hệ thống joomla 4. Tạo các controller cho component 5. Tạo submenu cho com_book 6. Tạo lệnh điều hướng đến các Controller 7. Xây dựng các class định nghĩa các bảng dữ liệu có trong component Giáo trình: Joomla! Programming Chuyên đề: Book shopping component Biên soạn: Phạm Vũ Khánh Email: vukhanh2212@gmail.com Điện thoại: 0908.893326 Website: www.zend.vn Tháng 08-2010 Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 2 Email: vukhanh2212@gmail.com 1. Phân tích Database Bảng jos_book_category Bảng chứa các danh mục sách (VD: PHP, ASP, Joomla!, Drupal …) Fields Type Decription id int(11) Khóa chính category varchar(200) Tên của category created_by int(11) ID người tạo category created datetime Ngày tạo modified_by int(11) ID người chỉnh sửa category modified datetime Ngày modify ordering int(11) Sắp xếp thứ tự hits int(11) Số lần xem published tinyint(1) Cho phép hiển thị SQL query: CREATE TABLE IF NOT EXISTS `jos_book_category` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category` varchar(200) NOT NULL, `created_by` int(11) NOT NULL, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) NOT NULL, `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `ordering` int(11) NOT NULL, `hits` int(11) NOT NULL, `published` tinyint(1) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Bảng jos_book Bảng chứa thông tin của sách theo từng các danh mục Fields Type Decription id int(11) Khóa chính title varchar(200) Tiêu đề quyển sách picture varchar(50) Hình ảnh quyển sách publish_date datetime Ngày xuất bản synopsis text Tóm tắt nội dung author varchar(150) Tác giả price varchar(50) Giá bạn publisher varchar(255) Nhà xuất bản content mediumtext Nội dung chính created_by int(11) ID người tạo (Khóa ngoại) created datetime Ngày tạo modified_by int(11) ID người chỉnh sửa (Khóa ngoại) modified datetime Ngày chỉnh sửa hits int(11) Số lần xem published tinyint(1) Cho phép hiển thị Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 3 Email: vukhanh2212@gmail.com catid int(11) ID của category (Khóa ngoại) SQL query: CREATE TABLE IF NOT EXISTS `jos_book` ( `id` int(11) NOT NULL AUTO_INCREMENT, `title` varchar(200) NOT NULL, `picture` varchar(50) NOT NULL, `publish_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `synopsis` text, `author` varchar(150) DEFAULT NULL, `price` varchar(50) NOT NULL, `publisher` varchar(255) DEFAULT NULL, `content` mediumtext NOT NULL, `created_by` int(11) NOT NULL, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `modified_by` int(11) NOT NULL DEFAULT '0', `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `hits` int(11) NOT NULL, `published` tinyint(1) NOT NULL DEFAULT '0', `catid` int(11) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Bảng jos_book_bill Bảng chứa thông tin khách hàng Fields Type Decription id int(11) Khóa chính created datetime Ngày tạo ra đơn đặt hàng full_name varchar(255) Tên người mua address text Địa chỉ người mua shipping text Địa chỉ giao hàng phone varchar(20) Số điện thoại mobi varchar(20) Số điện thoại di động comment text Thông tin status varchar(20) Trạng thái (pending – accept) SQL query: CREATE TABLE IF NOT EXISTS `jos_book_bill` ( `id` int(11) NOT NULL AUTO_INCREMENT, `created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `full_name` varchar(255) NOT NULL, `address` text NOT NULL, `shipping` text NOT NULL, `phone` varchar(20) NOT NULL, `mobi` varchar(20) NOT NULL, `comment` text NOT NULL, `status` varchar(20) NOT NULL DEFAULT 'pending', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Bảng jos_book_order Bảng chứa thông tin danh sách các cuốn sách được đặt hàng Fields Type Decription id int(11) Khóa chính của bảng bill_id int(11) ID của jos_book_bill book_id int(11) ID của cuốn sách Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 4 Email: vukhanh2212@gmail.com quantity int(11) Số lượng sách đặt mua price varchar(20) Giá của một cuốn sách SQL query: CREATE TABLE IF NOT EXISTS `jos_book_order` ( `id` int(11) NOT NULL AUTO_INCREMENT, `bill_id` int(11) NOT NULL, `book_id` int(11) NOT NULL, `quantity` int(11) NOT NULL, `price` varchar(20) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 5 Email: vukhanh2212@gmail.com 2. Xây dựng cấu trúc MVC cho Back-End của Joomla Tạo thư mục \com_book trong thư mục \joomla\administrator\components\ có cấu trúc như sau: Thư mục Giải thích \com_book\books Thư mục chứa hình ảnh những cuốn sách \com_book\controllers Thư mục chứa các controller của component \com_book\helper Thư mục chứa các tập tin hỗ trợ cho component (vd: nhưng Upload class, Image functions…) \com_book\tables Thư mục chứa các tập tin định nghĩa cho các Table của component \com_book\views Thư mục chứ các tập tin VIEW theo mô hình MVC của Joomla admin.book.php Tập tin chạy chính của component trong phần Back-End 3. Đăng ký com_book trong hệ thống joomla Vào phpMyAdmin truy cập database của Joomla Mở bảng jos_components. Nhấn nút Insert, sau đó thêm vào dữ liệu như sau Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 6 Email: vukhanh2212@gmail.com Thêm cho Menu chính (Components menu | Book) Thêm cho Menu phụ (Components menu | Book | Categories) Thêm cho Menu phụ (Components menu | Book | Books) Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 7 Email: vukhanh2212@gmail.com Thêm cho Menu phụ (Components menu | Book | Orders) 4. Tạo các controller cho component Tạo controller quản lý category: Tạo tập tin category.php trong \joomla\administrator\components\com_book\controllers\ với nội dung sau: <?php // Chong truy cap truc tiep defined( '_JEXEC' ) or die( 'Restricted access' ); //2. Goi lop ho tro controller jimport( 'joomla.application.component.controller' ); class BookControllerCategory extends JController{ function __construct( $default = array() ) { parent::__construct( $default ); } } ?> Tạo controller quản lý book: Tạo tập tin book.php trong \joomla\administrator\components\com_book\controllers\ với nội dung sau: <?php // Chong truy cap truc tiep defined( '_JEXEC' ) or die( 'Restricted access' ); //2. Goi lop ho tro controller jimport( 'joomla.application.component.controller' ); class BookControllerBook extends JController{ function __construct( $default = array() ) { parent::__construct( $default ); } } ?> Tạo controller quản lý các hóa đơn đặt hàng: Tạo tập tin order.php trong \joomla\administrator\components\com_book\controllers\ với nội dung sau: Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 8 Email: vukhanh2212@gmail.com <?php // Chong truy cap truc tiep defined( '_JEXEC' ) or die( 'Restricted access' ); //2. Goi lop ho tro controller jimport( 'joomla.application.component.controller' ); class BookControllerOrder extends JController{ function __construct( $default = array() ) { parent::__construct( $default ); } } ?> Để truy cập vào các controller của com_book chúng ta quy ước đường dẫn như sau: Truy cập category controller: http://localhost/joomla/administrator/index.php?option=com_book Truy cập book controller: http://localhost/joomla/administrator/index.php?option=com_book&c=Book Truy cập order controller: http://localhost/joomla/administrator/index.php?option=com_book&c=Order 5. Tạo submenu cho com_book Mở tập tin admin.book.php ở Back-End com_book thêm vào nội dung: <?php defined( '_JEXEC' ) or die( 'Restricted access' ); $controllerName = JRequest::getCmd( 'c', 'category' ); if($controllerName == 'category'){ JSubMenuHelper::addEntry(JText::_('Categories'), '',true ); JSubMenuHelper::addEntry(JText::_('Books'), 'index.php?option=com_book&c=Book'); JSubMenuHelper::addEntry(JText::_('Order'), 'index.php?option=com_book&c=Order' ); } if($controllerName == 'book'){ JSubMenuHelper::addEntry(JText::_('Categories'), 'index.php?option=com_book'); JSubMenuHelper::addEntry(JText::_('Books'), '',true ); JSubMenuHelper::addEntry(JText::_('Order'), 'index.php?option=com_book&c=Order' ); } if($controllerName == 'order'){ JSubMenuHelper::addEntry(JText::_('Categories'), 'index.php?option=com_book' ); Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 9 Email: vukhanh2212@gmail.com JSubMenuHelper::addEntry(JText::_('Books'), 'index.php?option=com_book&c=Book'); JSubMenuHelper::addEntry(JText::_('Order'), '',true ); } ?> 6. Tạo lệnh điều hướng đến các Controller Mở tập tin admin.book.php ở Back-End com_book thêm vào nội dung: <?php //Code cũ … require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' ); $controllerName = 'BookController'.$controllerName; // Create the controller $controller = new $controllerName(); // Perform the Request task $controller->execute( JRequest::getCmd('task') ); // Redirect if set by the controller $controller->redirect(); ?> Đồng thời thêm vào các class BookControllerBook – BookControllerCategory – BookControllerOrder một phương thức mới có nội dung sau: function display(){ echo __FUNCTION__ . ' in ' . __CLASS__; } 7. Xây dựng các class định nghĩa các bảng dữ liệu có trong component a. Tạo tập tin category.php Tạo tập tin category.php trong thư mục \joomla\administrator\components\com_book\tables\. Tập tin này chứa cấu trúc của bảng jos_book_category và những giá trị mặc định khi chúng ta sử dụng các field trong bảng với nội dung như sau: defined('_JEXEC') or die('Restricted Access'); class TableCategory extends JTable{ var $id = null; var $category = null; var $created_by = null; var $created = null; var $modified_by = null; var $modified = null; var $ordering = null; var $hits = null; var $published = 0; function __construct(&$db) { parent::__construct( '#__book_category', 'id', $db ); } } Ebook: L ập tr ình Joomla! 1.5 Zendvn Group Chương 1: Phân tích & xây d ựng hệ thống Back - End http://www.zend.vn Gi ảng vi ên: Ph ạm Vũ Kh ánh 10 Email: vukhanh2212@gmail.com b. Tạo tập tin book.php Tạo tập tin book.php trong thư mục \joomla\administrator\components\com_book\tables\. Tập tin này chứa cấu trúc của bảng jos_book và những giá trị mặc định khi chúng ta sử dụng các field trong bảng với nội dung như sau: defined('_JEXEC') or die('Restricted Access'); class TableBook extends JTable{ var $id = null; var $title = null; var $picture = null; var $publish_date = null; var $synopsis = null; var $author = null; var $price = null; var $publisher = null; var $content = null; var $created_by = null; var $created = null; var $modified_by = null; var $modified = null; var $hits = null; var $published = null; var $catid = 0; function __construct(&$db) { parent::__construct( '#__book', 'id', $db ); } } c. Tạo tập tin bill.php Tạo tập tin bill.php trong thư mục \joomla\administrator\components\com_book\tables\. Tập tin này chứa cấu trúc của bảng jos_book_bill và những giá trị mặc định khi chúng ta sử dụng các field trong bảng với nội dung như sau: defined('_JEXEC') or die('Restricted Access'); class TableBill extends JTable{ var $id = null; var $created = null; var $full_name = null; var $address = null; var $shipping = null; var $phone = null; var $mobi = null; var $comment = null; var $status = 'pendding'; function __construct(&$db) { parent::__construct( '#__book_bill', 'id', $db ); } } d. Tạo tập tin order.php [...]... Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Tạo tập tin category.php trong thư mục /com_book/views Tập tin này tương ứng với category controller của component Tập tin có nội dung như sau: class BookViewCategory{ function show(){ echo '' FUNCTION ' in ' CLASS ; } } Tạo một tập tin template có tên show.php tương... Xây dựng chức năng chỉnh sửa một category (task: edit – save - apply ) Giáo trình: Joomla! Programming Chuyên đề: Book shopping component Biên soạn: Phạm Vũ Khánh Email: vukhanh2212@gmail.com Điện thoại: 0908.893326 Website: www.zend.vn Tháng 08-2010 Giảng viên: Phạm Vũ Khánh 1 Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn...Ebook: Lập trình Joomla! 1.5 Chương 1: Phân tích & xây dựng hệ thống Back-End Zendvn Group http://www.zend.vn Tạo tập tin order.php trong thư mục \joomla\ administrator\components\com_book\tables\ Tập tin này chứa cấu trúc của bảng jos_book_order và những giá trị mặc định khi chúng ta sử dụng các field trong... dữ liệu FORM nhập liệu Trong hệ thống Joomla, đa số các form nhập liệu sử dụng Javascript để kiểm tra dữ liệu đầu vào Vì vậy để chúng ta nên chuẩn bị một tập tin Javascript chứa các hàm kiểm tra dữ liệu Giảng viên: Phạm Vũ Khánh 16 Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Tạo tập tin my_validate.js trong thư mục... bằng javascript Giảng viên: Phạm Vũ Khánh 20 Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Chúng ta có thể sử dụng lại FORM nhập liệu của chức năng add, nhưng cần một số thay đổi đối với FORM này Đưa tập tin my_validate.js vào Joomla Mở tập tin category.php trong thư mục /com_book/ views thêm vào hàm edit() với nội dung... Xây dựng chức năng chỉnh sửa một category (task: edit – save - apply ) Giáo trình: Joomla! Programming Chuyên đề: Book shopping component Biên soạn: Phạm Vũ Khánh Email: vukhanh2212@gmail.com Điện thoại: 0908.893326 Website: www.zend.vn Tháng 08-2010 Giảng viên: Phạm Vũ Khánh 1 Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 3: Xây dựng Book controller Zendvn Group http://www.zend.vn... Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Mở tập tin category.php trong thư mục /com_book/ views thêm vào hàm add() với nội dung sau: function add(){ BookViewCategory::setBookToolBar(); $lists = JHTML::_('select.booleanlist', 'published' ,'class="inputbox"',0, 'Publish','Unpublish'); require_once( TEMPLATE_VIEW DS 'add.php'); } Tạo tập tin add.php... viên: Phạm Vũ Khánh 6 Email: vukhanh2212@gmail.com Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Mở tập tin category.php trong thư mục /com_book views sửa hàm show() thành: function show($rows){ BookViewCategory::setBookCategoryToolBar(); require_once( TEMPLATE_VIEW.DS.'show.php'); } Mở tập tin Category.php trong thư mục /com_book/controllers sửa... Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn if(elem.value == val){ return false; }else{ return true; } } //Ham kiem tra du lieu la email function myEmailValidator(elem){ var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/; if(elem.value.match(emailExp)){ return true; }else{ return false; } } Để đưa một tập tin my_validate.js vào Joomla. .. Ebook: Lập trình Joomla! 1.5 Chương 2: Xây dựng Category controller Zendvn Group http://www.zend.vn Thêm đường dẫn đến thư mục chứa cấu trúc bảng Mở tập tin admin.book php trong thư mục /com_book thêm vào nội dung sau : defined( '_JEXEC' ) or die( 'Restricted access' ); JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_book'.DS.'tables'); //Code cũ Lưu dữ liệu vào Database Mở tập tin . created_by int (11 ) ID người tạo category created datetime Ngày tạo modified_by int (11 ) ID người chỉnh sửa category modified datetime Ngày modify ordering int (11 ) Sắp xếp thứ tự hits int (11 ) Số lần. modified_by int (11 ) ID người chỉnh sửa (Khóa ngoại) modified datetime Ngày chỉnh sửa hits int (11 ) Số lần xem published tinyint (1) Cho phép hiển thị Ebook: L ập tr ình Joomla! 1. 5 Zendvn. `modified_by` int (11 ) NOT NULL, `modified` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', `ordering` int (11 ) NOT NULL, `hits` int (11 ) NOT NULL, `published` tinyint (1) NOT NULL DEFAULT

Ngày đăng: 14/04/2014, 10:49

Từ khóa liên quan

Mục lục

  • 001-Dang ky component trong database.pdf (p.1-11)

  • 002-cac-buoc-xay-dung-Category.pdf (p.12-33)

  • 003-cac-buoc-xay-dung-Book-controller.pdf (p.34-56)

  • 004-xay-dung-component-front-end.pdf (p.57-66)

  • 005-xay-dung-task-show-all-category.pdf (p.67-71)

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan