我直接参考了joomla 自带的组件:com_banners(administrator\components\com_banners)的代码. 个人觉得1.5版本的目录还是比较随意的,但很符合MVC三层的概念. 自己还没开始做组件,想先等研究透了再说.
controllers/
elements/
helpers/
tables/
views/
admin.banners.php
banners.xml
config.xml
index.html

1. index.html 空文件不做任何处理

2. config.xml 配置文件,如果没有特别的配置可以不需要这个文件

3. banners.xml 这个是安装以及卸载时要上传的文件以及SQL语句.跟1.0差不多.banners组件基本上啥都没, 所以用另外一个组件来分析下

joomla 笔记(二)<?xml version="1.0" encoding="utf-8"?>
joomla 笔记(二)
<!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/component-install.dtd">
joomla 笔记(二)
<install type="component" version="1.5.0">
joomla 笔记(二)  
<name>helloworld</name><!--组件名字-->
joomla 笔记(二)  
<!-- The following elements are optional and free of formatting conttraints -->
joomla 笔记(二)  
<creationDate>February 2008</creationDate><!--组件创建时间-->
joomla 笔记(二)  
<author>Petr Vojtechovsky</author><!--作者-->
joomla 笔记(二)  
<authorEmail>vojtechovsky@gmail.com</authorEmail><!--EMAIL-->
joomla 笔记(二)  
<authorUrl>http://www.vojtechovsky.net</authorUrl><!--网站-->
joomla 笔记(二)  
<copyright>(C) 2007 All rights reserved.</copyright>
joomla 笔记(二)  
<license>GNU/GPL</license> <!--这个不要修改-->
joomla 笔记(二)  
<!--  The version string is recorded in the components table -->
joomla 笔记(二)  
<version>1.5.0</version><!--版本,这个也不要修改-->
joomla 笔记(二)  
<!-- The description is optional and defaults to the name 描述 出现在安装成功后的一些提示-->
joomla 笔记(二)  
<description><![CDATA[<p>write you description here! And it will show when you install this component!</p>]]></description>
joomla 笔记(二)  
<install>
joomla 笔记(二)    
<sql folder="admin/sql"><!--folder="admin/sql" SQL语句文件在安装包的文件所在位置-->
joomla 笔记(二)      
<file driver="mysql" charset="utf8">install.helloworld.sql</file>
joomla 笔记(二)    
</sql>
joomla 笔记(二)  
</install>
joomla 笔记(二)  
<uninstall>
joomla 笔记(二)    
<sql  folder="admin/sql">
joomla 笔记(二)      
<file driver="mysql" charset="utf8">uninstall.helloworld.sql</file>
joomla 笔记(二)    
</sql>
joomla 笔记(二)  
</uninstall>
joomla 笔记(二) 
joomla 笔记(二)  
<!--前台要安装的文件-->
joomla 笔记(二)  
<files folder="component">
joomla 笔记(二)    
<filename>index.html</filename>
joomla 笔记(二)    
<filename>helloworld.php</filename>
joomla 笔记(二)  
</files>
joomla 笔记(二)  
joomla 笔记(二)  
<languages folder="component/lang">
joomla 笔记(二)    
<language tag="en-GB">en-GB.com_helloworld.ini</language>
joomla 笔记(二)    
<language tag="cs-CZ">cs-CZ.com_helloworld.ini</language>
joomla 笔记(二)  
</languages>
joomla 笔记(二)  
joomla 笔记(二)  
<!--后台要安装的文件-->
joomla 笔记(二)  
<administration>
joomla 笔记(二)    
<!-- Administration Menu Section 后台的菜单-->
joomla 笔记(二)    
<menu img="components/com_helloworld/images/helloworld.png">Hello World</menu>
joomla 笔记(二)    
<submenu>
joomla 笔记(二)      
<!-- Note that all & must be escaped to &amp; for the file to be valid XML and be parsed by the installer 需要子菜单的必须把连接写上去,并且要求&符号用&amp;代替-->
joomla 笔记(二)      
<menu link="option=com_helloworld&amp;controller=helloworld">Hello World!</menu>
joomla 笔记(二)      
<menu link="option=com_helloworld&amp;controller=helloagain">Hello Again!</menu>
joomla 笔记(二)      
<menu link="option=com_helloworld&amp;controller=hellotestfoo">Testing Foo Function</menu>
joomla 笔记(二)    
</submenu>
joomla 笔记(二)    
<!-- Administration Main File Copy Section -->
joomla 笔记(二)    
<!-- Note the folder attribute: This attribute describes the folder to copy FROM in the package to install therefore files copied in this section are copied from /admin/ in the package -->
joomla 笔记(二)    
<files folder="admin">
joomla 笔记(二)      
<filename>index.html</filename>
joomla 笔记(二)      
<filename>admin.helloworld.php</filename>
joomla 笔记(二)      
<filename>toolbar.helloworld.php</filename>
joomla 笔记(二)      
<filename>toolbar.helloworld.html.php</filename>
joomla 笔记(二)      
joomla 笔记(二)      
<!-- install controllers -->
joomla 笔记(二)      
<filename>controllers/default.php</filename>
joomla 笔记(二)      
<filename>controllers/helloagain.php</filename>
joomla 笔记(二)      
<filename>controllers/hellotestfoo.php</filename>
joomla 笔记(二)      
<filename>controllers/helloworld.php</filename>
joomla 笔记(二)      
joomla 笔记(二)      
<!-- install model - one for all -->
joomla 笔记(二)      
<filename>models/helloworld.php</filename>
joomla 笔记(二)      
joomla 笔记(二)      
<!-- install views -->
joomla 笔记(二)      
<filename>views/default/view.php</filename>
joomla 笔记(二)      
<filename>views/helloagain/view.php</filename>
joomla 笔记(二)      
<filename>views/hellotestfoo/view.php</filename>
joomla 笔记(二)      
<filename>views/helloworld/view.php</filename>
joomla 笔记(二)      
<filename>images/helloworld.png</filename>
joomla 笔记(二)    
</files>
joomla 笔记(二)    
joomla 笔记(二)    
<files folder="admin/sql">
joomla 笔记(二)      
<!-- database script -->
joomla 笔记(二)      
<filename>install.helloworld.sql</filename>
joomla 笔记(二)      
<filename>uninstall.helloworld.sql</filename>
joomla 笔记(二)    
</files>
joomla 笔记(二) 
joomla 笔记(二)    
<!-- Administration Language File Copy Section -->
joomla 笔记(二)    
<languages folder="admin/lang">
joomla 笔记(二)      
<language tag="en-GB">en-GB.com_helloworld.ini</language>
joomla 笔记(二)      
<language tag="cs-CZ">cs-CZ.com_helloworld.ini</language>
joomla 笔记(二)    
</languages>
joomla 笔记(二)  
</administration>
joomla 笔记(二)
</install>

4.admin.banners.php 这个文件的主要作用就是把MVC三层里面的文件调用起来.
M:是指数据库的类文件,文件夹可以为table, module
table文件夹里的文件class TableBanner extends JTable 继承 JTable, TableBanner定义表的基本字段,表字段的检查函数比如check, 并可以重写JTable里面的函数;
module文件夹里的文件class ModuleBanner extends JModel 继承 JModel

C:连接M和V的控制层, controllers里面的类文件. $row =& JTable::getInstance('banner', 'Table');生成数据库类的实例对表进行操作, require_once(JPATH_COMPONENT.DS.'views'.DS.'banner.php');把HTML页面包含进来.

V:视图层,HTML代码页面.

joomla 笔记(二)<?php
joomla 笔记(二)
/**
joomla 笔记(二) * @version        $Id: admin.banners.php 10381 2008-06-01 03:35:53Z pasamio $
joomla 笔记(二) * @package        Joomla
joomla 笔记(二) * @subpackage    Banners
joomla 笔记(二) * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
joomla 笔记(二) * @license        GNU/GPL, see LICENSE.php
joomla 笔记(二) * Joomla! is free software. This version may have been modified pursuant
joomla 笔记(二) * to the GNU General Public License, and as distributed it includes or
joomla 笔记(二) * is derivative of works licensed under the GNU General Public License or
joomla 笔记(二) * other free or open source software licenses.
joomla 笔记(二) * See COPYRIGHT.php for copyright notices and details.
joomla 笔记(二) 
*/
joomla 笔记(二)
joomla 笔记(二)
// no direct access 单入口控制
joomla 笔记(二)
defined'_JEXEC' ) or die'Restricted access' );
joomla 笔记(二)
joomla 笔记(二)
// Make sure the user is authorized to view this page
joomla 笔记(二)//确认该用户访问此组件的权限

joomla 笔记(二)
$user = & JFactory::getUser();
joomla 笔记(二)
if (!$user->authorize( 'com_banners', 'manage' )) {
joomla 笔记(二)    
$mainframe->redirect( 'index.php', JText::_('ALERTNOTAUTH') );
joomla 笔记(二)}
joomla 笔记(二)
joomla 笔记(二)
// Set the table directory
joomla 笔记(二)//把组件的数据库表类包括进来

joomla 笔记(二)
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_banners'.DS.'tables');
joomla 笔记(二)
joomla 笔记(二)
//获取URL(joomla 笔记(二)/administrator/index.php?option=com_banners&c=client)中controller的内容
joomla 笔记(二)
$controllerName = JRequest::getCmd( 'c', 'banner' );
joomla 笔记(二)
joomla 笔记(二)
if($controllerName == 'client') {
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Banners'), 'index.php?option=com_banners');
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Clients'), 'index.php?option=com_banners&c=client', true );
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Categories'), 'index.php?option=com_categories&section=com_banner');
joomla 笔记(二)
else {
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Banners'), 'index.php?option=com_banners', true );
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Clients'), 'index.php?option=com_banners&c=client');
joomla 笔记(二)    JSubMenuHelper
::addEntry(JText::_('Categories'), 'index.php?option=com_categories&section=com_banner');
joomla 笔记(二)}
joomla 笔记(二)
joomla 笔记(二)
switch ($controllerName)
joomla 笔记(二){
joomla 笔记(二)    
default:
joomla 笔记(二)        
$controllerName = 'banner';
joomla 笔记(二)        
// allow fall through
joomla 笔记(二)

joomla 笔记(二)    
case 'banner' :
joomla 笔记(二)    
case 'client':
joomla 笔记(二)        
// Temporary interceptor
joomla 笔记(二)
        $task = JRequest::getCmd('task');
joomla 笔记(二)        
if ($task == 'listclients') {
joomla 笔记(二)            
$controllerName = 'client';
joomla 笔记(二)        }
joomla 笔记(二)        
joomla 笔记(二)        
//通过controller决定调用controllers里的哪个文件
joomla 笔记(二)
        require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
joomla 笔记(二)        
$controllerName = 'BannerController'.$controllerName;
joomla 笔记(二)
joomla 笔记(二)        
// Create the controller
joomla 笔记(二)
        $controller = new $controllerName();
joomla 笔记(二)
joomla 笔记(二)        
// Perform the Request task调用controller层定义的函数,如果task为空的话就直接执行控制层里定义的'display'方法
joomla 笔记(二)        $controller->execute( JRequest::getCmd('task') );
joomla 笔记(二)
joomla 笔记(二)        
// Redirect if set by the controller
joomla 笔记(二)
        $controller->redirect();
joomla 笔记(二)        
break;
joomla 笔记(二)}
joomla 笔记(二)
?>

5. tables/
上面说过这个文件夹下面是数据库类文件, 一般以数据库表命名(jos_banner) banner.php

joomla 笔记(二)<?php
joomla 笔记(二)
/**
joomla 笔记(二) * @version        $Id: banner.php 10381 2008-06-01 03:35:53Z pasamio $
joomla 笔记(二) * @package        Joomla
joomla 笔记(二) * @subpackage    Banners
joomla 笔记(二) * @copyright    Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
joomla 笔记(二) * @license        GNU/GPL, see LICENSE.php
joomla 笔记(二) * Joomla! is free software. This version may have been modified pursuant
joomla 笔记(二) * to the GNU General Public License, and as distributed it includes or
joomla 笔记(二) * is derivative of works licensed under the GNU General Public License or
joomla 笔记(二) * other free or open source software licenses.
joomla 笔记(二) * See COPYRIGHT.php for copyright notices and details.
joomla 笔记(二) 
*/
joomla 笔记(二)
joomla 笔记(二)
// no direct access
joomla 笔记(二)
defined'_JEXEC' ) or die'Restricted access' );
joomla 笔记(二)
joomla 笔记(二)
/**
joomla 笔记(二) * @package        Joomla
joomla 笔记(二) * @subpackage    Banners
joomla 笔记(二) 
*/
joomla 笔记(二)
class TableBanner extends JTable
joomla 笔记(二){
joomla 笔记(二)    
//下面的类的私有属性都是数据库表的字段,并赋上初始化的值, 一般都是null,0,''
joomla 笔记(二)
    /** @var int */
joomla 笔记(二)    
var $bid                = null;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $cid                = null;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $type                = '';
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $name                = '';
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $alias                = '';
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $imptotal            = 0;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $impmade            = 0;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $clicks                = 0;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $imageurl            = '';
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $clickurl            = '';
joomla 笔记(二)    
/** @var date */
joomla 笔记(二)    
var $date                = null;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $showBanner            = 0;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $checked_out        = 0;
joomla 笔记(二)    
/** @var date */
joomla 笔记(二)    
var $checked_out_time    = 0;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $editor                = '';
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $custombannercode    = '';
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $catid                = null;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $description        = null;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $sticky                = null;
joomla 笔记(二)    
/** @var int */
joomla 笔记(二)    
var $ordering            = null;
joomla 笔记(二)    
/** @var date */
joomla 笔记(二)    
var $publish_up            = null;
joomla 笔记(二)    
/** @var date */
joomla 笔记(二)    
var $publish_down        = null;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $tags                = null;
joomla 笔记(二)    
/** @var string */
joomla 笔记(二)    
var $params                = null;
joomla 笔记(二)    
joomla 笔记(二)    
//构造函数.
joomla 笔记(二)
    function __construct( &$_db )
joomla 笔记(二)    {
joomla 笔记(二)        parent
::__construct( '#__banner', 'bid', $_db );
joomla 笔记(二)
joomla 笔记(二)
joomla 笔记(二)        
$now =& JFactory::getDate();
joomla 笔记(二)        
$this->set( 'date', $now->toMySQL() );
joomla 笔记(二)    }
joomla 笔记(二)
joomla 笔记(二)    
function clicks()
joomla 笔记(二)    {
joomla 笔记(二)        
$query = 'UPDATE #__banner'
joomla 笔记(二)        
. ' SET clicks = ( clicks + 1 )'
joomla 笔记(二)        
. ' WHERE bid = ' . (int) $this->bid
joomla 笔记(二)        ;
joomla 笔记(二)        
$this->_db->setQuery( $query );
joomla 笔记(二)        
$this->_db->query();
joomla 笔记(二)    }
joomla 笔记(二)
joomla 笔记(二)    
/**
joomla 笔记(二)     * Overloaded check function
joomla 笔记(二)     *
joomla 笔记(二)     * @access public
joomla 笔记(二)     * @return boolean
joomla 笔记(二)     * @see JTable::check
joomla 笔记(二)     * @since 1.5
joomla 笔记(二)     * 确认传递进来的字段值是否合法
joomla 笔记(二)     
*/
joomla 笔记(二)    
function check()
joomla 笔记(二)    {
joomla 笔记(二)        
// check for valid client id
joomla 笔记(二)
        if (is_null($this->cid) || $this->cid == 0) {
joomla 笔记(二)            
$this->setError(JText::_( 'BNR_CLIENT' ));
joomla 笔记(二)            
return false;
joomla 笔记(二)        }
joomla 笔记(二)
joomla 笔记(二)        
// check for valid name
joomla 笔记(二)
        if(trim($this->name) == '') {
joomla 笔记(二)            
$this->setError(JText::_( 'BNR_NAME' ));
joomla 笔记(二)            
return false;
joomla 笔记(二)        }
joomla 笔记(二)
joomla 笔记(二)        
if(empty($this->alias)) {
joomla 笔记(二)            
$this->alias = $this->name;
joomla 笔记(二)        }
joomla 笔记(二)        
$this->alias = JFilterOutput::stringURLSafe($this->alias);
joomla 笔记(二)
joomla 笔记(二)        
/*if(trim($this->imageurl) == '') {
joomla 笔记(二)            $this->setError(JText::_( 'BNR_IMAGE' ));
joomla 笔记(二)            return false;
joomla 笔记(二)        }
joomla 笔记(二)        if(trim($this->clickurl) == '' && trim($this->custombannercode) == '') {
joomla 笔记(二)            $this->setError(JText::_( 'BNR_URL' ));
joomla 笔记(二)            return false;
joomla 笔记(二)        }
*/
joomla 笔记(二)
joomla 笔记(二)        
return true;
joomla 笔记(二)    }
joomla 笔记(二)}
joomla 笔记(二)
?>


 

相关文章:

  • 2021-10-17
  • 2022-12-23
  • 2021-10-18
  • 2021-07-05
  • 2021-12-21
  • 2021-07-18
  • 2022-12-23
  • 2021-07-31
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-29
  • 2022-02-01
  • 2022-12-23
相关资源
相似解决方案