??xml version="1.0" encoding="utf-8" standalone="yes"?>91九色成人,精品日韩在线一区,欧美大片免费久久精品三phttp://www.aygfsteel.com/tonyzhou00/category/8157.htmlzh-cnThu, 19 Jul 2007 11:26:38 GMTThu, 19 Jul 2007 11:26:38 GMT60L开发自qlg http://www.aygfsteel.com/tonyzhou00/articles/34007.html蛮哥♂枫蛮哥♂枫Tue, 07 Mar 2006 02:55:00 GMThttp://www.aygfsteel.com/tonyzhou00/articles/34007.htmlhttp://www.aygfsteel.com/tonyzhou00/comments/34007.htmlhttp://www.aygfsteel.com/tonyzhou00/articles/34007.html#Feedback0http://www.aygfsteel.com/tonyzhou00/comments/commentRss/34007.htmlhttp://www.aygfsteel.com/tonyzhou00/services/trackbacks/34007.html? 本教E非原创,版权归Keliix06所?

快速创Z个简单的MAMBOlg
作者:Keliix06
译者:Applebee
本教E将安装一个“Hello World”组Ӟ你可以去~辑或者加入你自己惌的消息。本教程不涉及如何设|分c,搜烦功能和页面导航。ƈ假定你对PHP有一个基本的了解?
创徏本组件将用到以下文gQ?
hello_world.xml- lg安装配置文g
hello_world.php- 昄界面信息
admin.hello_world.php- 数据库查询和讄HTML输出
admin.hello_world.html.php- 控制所有的输出
class.hello_world.php- 数据库类文g
install.hello_world.php- 安装文g
uninstall.hello_world.php- 卸蝲文g
toolbar.hello_world.php- 讄工具?
toolbar.hello_world.html.php- 控制工具栏的输出

现在我们已经清楚了要制作什么样的文Ӟ下面我们一个文件一个文件的介绍它们如何实现各自的功能?


Hello_world.xml- lg安装配置文g

<?xml version="1.0" ?>
<mosinstall type="component">
<name>hello_world</name>
<creationDate>04/15/2004</creationDate>
<author>Doyle Lewis</author>
<copyright>This component in released under the GNU/GPL License</copyright>
<authorEmail> support@mambo-hosting.com

</authorEmail>
<authorUrl>www.mambo-hosting.com</authorUrl>
<version>1.0</version>
<files>
<filename>hello_world.php</filename>
</files>
<install>
<queries>
<query>DROP TABLE IF EXISTS `mos_hello_world`;</query>
<query>CREATE TABLE `mos_hello_world` (
`id` INT NOT NULL AUTO_INCREMENT,
`text` TEXT NOT NULL,
`published` TINYINT(1) NOT NULL,
PRIMARY KEY (`id`)
)
</query>
</queries>
</install>
<uninstall>
<queries>
<query>DROP TABLE IF EXISTS `mos_hello_world`;</query>
</queries>
</uninstall>
<installfile>
<filename>install.hello_world.php</filename>
</installfile>
<uninstallfile>
<filename>uninstall.hello_world.php</filename>
</uninstallfile>
<administration>
<menu>Hello World</menu>
<submenu>
<menu act="all">Show Text</menu>
</submenu>
<files>
<filename>admin.hello_world.php</filename>
<filename>admin.hello_world.html.php</filename>
<filename>class.hello_world.php</filename>
<filename>toolbar.hello_world.php</filename>
<filename>toolbar.hello_world.html.php</filename>
</files>
</administration>
</mosinstall>

我们来看它是如何工作的:

<?xml version="1.0" ?>
XML的开头语Qؓ所有XML文g所必需?

<mosinstall type="component">
告诉MAMBO开始安装一个组?

<name>hello_world</name>
<creationDate>04/15/2004</creationDate>
<author>Doyle Lewis</author>
<copyright>This component in released under the GNU/GPL License</copyright>
<authorEmail> support@mambo-hosting.com

</authorEmail>
<authorUrl>www.mambo-hosting.com</authorUrl>
<version>1.0</version>
lg的详l信息,所有有关组件的信息只能在这加入?

<files>
<filename>hello_world.php</filename>
</files>
所有需要安装在lg界面需要的文gQ将被安装到components/com_hello_world/目录下?

<install>
<queries>
<query>DROP TABLE IF EXISTS `mos_hello_world`;</query>
<query>CREATE TABLE `mos_hello_world` (
`id` INT NOT NULL AUTO_INCREMENT,
`text` TEXT NOT NULL,
`published` TINYINT(1) NOT NULL,
PRIMARY KEY (`id`)
)
</query>
</queries>
</install>
安装lg所需的数据库查询语句Q本lg中将创徏一个有三个字段的表。你可以q行phpMyadmin来得C所需的查询语句的Q这是一个很单易行的办法?

<uninstall>
<queries>
<query>DROP TABLE IF EXISTS `mos_hello_world`;</query>
</queries>
</uninstall>
卸蝲lg所需的查询语句,q里只是单的删除了数据库表格?

<installfile>
<filename>install.hello_world.php</filename>
</installfile>
<uninstallfile>
<filename>uninstall.hello_world.php</filename>
</uninstallfile>
q几行代码是用来说明安装和卸载组件所用到的文件名?

<administration>
从这行v所有的东东安装到理员目录下?

<menu>Hello World</menu>
q行被昄到管理面板中的“组件”的下拉菜单中?

<submenu>
<menu act="all">Show Text</menu>
</submenu>
q几行代码将产生一个二U菜单(相对于刚才生的Hello World菜单选项Q,q也告诉MAMBO你的lg有些什么功能?
<files>
<filename>admin.hello_world.php</filename>
<filename>admin.hello_world.html.php</filename>
<filename>class.hello_world.php</filename>
<filename>toolbar.hello_world.php</filename>
<filename>toolbar.hello_world.html.php</filename>
</files>
所有将被安装到administrator/components/com_hello_world/目录下的文g?

</administration>
</mosinstall>
l束MAMBOlg安装

hello_world.php-界面昄文g

<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
global $database;
$query = "SELECT * FROM mos_hello_world LIMIT 1";
$database->setQuery( $query );
$rows = $database->loadObjectList();
$row = $rows[0];
echo $row->text;
?>

让我们来看一下这个文件?

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
q个验证是否由MAMBO来调用此文gQ防止非法直接运行本文gQ对于安全性非帔R要?

global $database;
?database讄为全局变量Q你可以在你的函C使用$database?
$query = "SELECT * FROM mos_hello_world LIMIT 1";
输出mos_hello_world表中的第一个记录?

$database->setQuery( $query );
用databasecM的数据库查询函数调用上述的查询?

$rows = $database->loadObjectList();
用变?rows 以数列方式存储查询结果?

$row = $rows[0];
用变?$row 存储$row中的W一个元素?

echo $row->text;
打印输出text.

admin.hello_world.php -数据库查询和讄HTML输出
<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
require_once($mosConfig_absolute_path."/administrator/components/com_hello_world/class.hello_world.php");
require_once( $mainframe->getPath( 'admin_html' ) );
switch ($act) {
default:
$task = "showText";
break;
}
switch ($task) {
case "save":
save( $option );
break;
case "delete":
delete( $option, $id );
break;
case "new":
$id = '';
edit( $option, $id );
break;
case "edit":
save( $option, $id[0] );
break;
case "showText":
showText( $option );
break;
}
function save( $option ) {
global $database;
$row = new mosHello_world( $database );
if (!$row->bind( $_POST )) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>n";
exit();
}
if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>n";
exit();
}
mosRedirect( "index2.php?option=$option", "Saved" );
}
function edit( $option, $uid ) {
global $database;
$row = new mosHello_world( $database );
$row->load( $uid );
HTML_hello_world::edit( $option, $row );
}
function delete( $option, $cid ) {
global $database;
if (!is_array( $cid ) || count( $cid ) < 1) {
echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>n";
exit;
}
if (count( $cid )) {
$cids = implode( ',', $cid );
$database->setQuery( "DELETE FROM mos_hello_world WHERE id IN ($cids)" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>n";
}
}
mosRedirect( "index2.php?option=$option" );
}
function showText($option) {
global $database;
# Do the main database query
$database->setQuery( "SELECT * FROM mos_hello_world ORDER BY id" );
$rows = $database->loadObjectList();
if ($database->getErrorNum()) {
echo $database->stderr();
return false;
}
HTML_hello_world::showText( $option, $rows );
}
让我们来看看q个文g
:
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
q个验证是否由MAMBO来调用此文gQ防止非法直接运行本文gQ对于安全性非帔R要?

require_once($mosConfig_absolute_path."/administrator/components/com_hello_world/class.hello_world.php");
require_once( $mainframe->getPath( 'admin_html' ) );
调用以下两文?class.hello_world.php and admin.hello_world.html.php

switch ($act) {
default:
$task = "showText";
break;
}
建立一个选择开兌句这样假如有一个变?act 我们重定义一个新变量$task. q样$act 用来实现显C文字的函数中,?task被用在保存Q删除等?

switch ($task) {
case "save":
save( $option );
break;
case "delete":
delete( $option, $id );
break;
case "new":
$id = '';
edit( $option, $id );
break;
case "edit":
save( $option, $id[0] );
break;
case "showText":
showText( $option );
break;
}
q个开兌句将Ҏ$task来运行所需的函数?

function save( $option ) {
我们的第一个函敎ͼ保存我们创建或正在~辑的内宏V?

global $database;
声明$database为全局变量?

$row = new mosHello_world( $database );
q将定义$row新变量来存储插入到数据库中的信息Q?row是class class.hello_world.php文g定义的mosHello_worldcȝ一个实例?

if (!$row->bind( $_POST )) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>n";
exit();
}
假如 $row q回I|昄错误信息q返回上一个窗口?

if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>n";
exit();
}
假如不能完成Ҏ据库的写操作Q将昄错误信息q返回上一个窗口,q仅仅会在数据库出现异常时会出现?

mosRedirect( "index2.php?option=$option", "Saved" );
假如一切正常将重定向你的浏览器C选项H口Qƈ昄"Saved".

function edit( $option, $uid ) {
很多代码可参照前面的解释Q这里不再赘q?

$row->load( $uid );
定义?row后ƈ声明它ؓmosHello_worldc?装蝲$uid相关的数? $uid?
我们想编辑的内容?id的倹{?

HTML_hello_world::edit( $option, $row );
?row 传递到admin.hello_world.html.php 昄?
.
function delete( $option, $cid ) {
同前Q这里不再赘q?

if (!is_array( $cid ) || count( $cid ) < 1) {
echo "<script> alert('Select an item to delete'); window.history.go(-1);</script>n";
exit;
}
q将验是否有删除对象Q如为空显C提CZ息ƈq回上一个窗口?

if (count( $cid )) {
$cids = implode( ',', $cid );
$database->setQuery( "DELETE FROM mos_hello_world WHERE id IN ($cids)" );
if (!$database->query()) {
echo "<script> alert('".$database->getErrorMsg()."'); window.history.go(-1); </script>n";
}
q将?cid (存储所有欲删除的对象的$id值的数列)是否为空Q如果不为空它将创徏一个以逗号为分隔符的所有id的列表ƈ存储在字W串$cids然后Ҏ相应的idq行删除操作Q如果操作出错将q回上一个窗口?

function showText($option) {
q是我们的主输出函数Q将创徏我们要输出的文字的列表,解释参照前面所q?

admin.hello_world.html.php –控制所有的输出.
<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
// ensure this file is being included by a parent file
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
require_once($mosConfig_absolute_path."/administrator/components/com_hello_world/class.hello_world.php");
class HTML_hello_world {
function edit( $option, &$row ) {
?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == "cancel") {
submitform( pressbutton );
return;
}
submitform( pressbutton );
}
</script>
<form action="index2.php" method="post" name="adminForm" id="adminForm" class="adminForm">
<table border="0" cellpadding="3" cellspacing="0">
<tr>
<td>Text Output: </td>
<td><input type="text" size="50" maxsize="100" name="text" value="<?php echo $row->text; ?>" /></td>
</tr>
</table>
<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="task" value="" />
</form>
<?php } ?>
function showText( $option, &$rows ) {
?>
<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == "cancel") {
submitform( pressbutton );
return;
}
submitform( pressbutton );
}
</script>
<form action="index2.php" method="post" name="adminForm">
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="adminlist">
<tr>
<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);"
/></th>
<th class="title" width="25%">Text Output</th>
<th width="25%">Published</th>
</tr>
<?php
$k = 0;
for($i=0; $i < count( $rows ); $i++) {
$row = $rows[$i];
?>
<tr class="<?php echo "row$k"; ?>">
<td><input type="checkbox" id="cb<?php echo $i;?>" name="id[]" value="<?php echo $row->id; ?>"
onclick="isChecked(this.checked);" /></td>
<td><a onclick="return listItemTask('cb<?php echo $i;?>','edit')"><?php echo $row->text; ?></a></td>
<td align="center">
<?php
if ($row->published == "1") {
echo "<img src="images/tick.png" border="0" />";
} else {
echo "<img src="images/publish_x.png" border="0" />";
}
?>
</td>
<?php $k = 1 - $k; ?>
</tr>
<?php } ?>
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
</form>
<?php }
} ?>

我们来看一下这个文?
class HTML_hello_world {
声明一个新c:HTML_hello_world

function edit( $option, &$row ) {
声明edit函数Q?显C用来创建新内容q编辑已有的内容的表单?

<script language="javascript" type="text/javascript">
function submitbutton(pressbutton) {
var form = document.adminForm;
if (pressbutton == "cancel") {
submitform( pressbutton );
return;
}
submitform( pressbutton );
}
</script>
q将验你是否按下了Q何工h的按钮,你可以加入Q何表单验证代码在q里?

<form action="index2.php" method="post" name="adminForm" id="adminForm" class="adminForm">
你可以将q段代码拯CQ何组件中Q它必须包括q些标签?

<input type="hidden" name="id" value="<?php echo $row->id; ?>" />
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="task" value="" />
保存或取消操作所必须的option和task字段?

function showText( $option, &$rows ) {
显C所有的文字部分?

<th width="20"><input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($rows); ?>);"
/></th>
q将快速全选所有的选择框?

<?php
$k = 0;
for($i=0; $i < count( $rows ); $i++) {
$row = $rows[$i];
$k用来产生行的替换图效果,for 语句保证遍列所有的l果?

<td><input type="checkbox" id="cb<?php echo $i;?>" name="id[]" value="<?php echo $row->id; ?>"
onclick="isChecked(this.checked);" /></td>
q将选上本行的选择框?

<td><a onclick="return listItemTask('cb<?php echo $i;?>','edit)"><?php echo $row->text; ?></a></td>
生编辑此的链接?

<?php
if ($row->published == "1") {
echo "<img src="images/tick.png" border="0" />";
} else {
echo "<img src="images/publish_x.png" border="0" />";
}
?>
假如此行被设|ؓ发行Q你看C个绿的叉Q否则将看到一个小U叉?

<?php $k = 1 - $k; ?>
?$k设ؓ 1和它自n的差|假如$k?0Q它q?Q假如它{于1它就被设?.

<input type="hidden" name="boxchecked" value="0" />
q行代码很重要不然所有的选择框将不能正常工作?


class.hello_world.php -数据库类文g.
<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
class mosHello_world extends mosDBTable {
// INT(11) AUTO_INCREMENT
var $id=null;
// TEXT
var $text=null;
// TINYINT(1)
var $published=null;
function mosHello_world( &$db ) {
$this->mosDBTable( 'mos_hello_world', 'id', $db );
}
}

我们来看一下这个文?

class mosHello_world extends mosDBTable {
声明cmosHello_world为mosDBTable的派生类Q你可以mosHello_worldҎ你自qcdU?

// INT(11) AUTO_INCREMENT
var $id=null;
注释行只是给Z变量的一些信息,变量名必d你数据库的相应字D늛W合q将它们设ؓI倹{?

function mosHello_world( &$db ) {
$this->mosDBTable( 'mos_hello_world', 'id', $db );
}
调用父类的构造函敎ͼ你可以调?row=new mosHello_world($database)来得到想要的l果?
install.hello_world.php ?安装文g.
<?php
function com_install() {
echo "Thank you for using this component. Please contact me at support@mambo-hosting.com

with any questions";
}
?>
在文件中调用函数com_install()Q不然会D异常?

uninstall.hello_world.php ?卸蝲文g.
<?
function com_uninstall() {
echo "Thank you for using this component. Please contact me at support@mambo-hosting.com

with any questions";
}
?>
在文件中调用函数com_uninstall()Q不然会D异常?

toolbar.hello_world.php -讄工具?
<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
require_once( $mainframe->getPath( 'toolbar_html' ) );
if($task) {
switch($task) {
case 'new':
case 'edit':
$act = "edit";
break;
}
}
if ($act) {
switch ( $act ) {
case 'edit':
menuHello_world::EDIT_MENU();
break;
case 'text':
menuHello_world::TEXT_MENU();
break;
}
}
?>
我们来看一下这个文?

require_once( $mainframe->getPath( 'toolbar_html' ) );
和在admin.hello_world.php中包括admin.hello_world.html.php一?

if($task) {
switch($task) {
case 'new':
case 'edit':
$act = "edit";
break;
}
}
"new" ?edit" 应用相同的工具栏?

case 'edit':
menuHello_world::EDIT_MENU();
break;
告诉toolbar.hello_world.html.php 该调用哪个函数?


toolbar.hello_world.html.php -控制工具栏的输出
<?php
//hello_world Component//
/**
* Content code
* @package hello_world
* @Copyright (C) 2004 Doyle Lewis
* @ All rights reserved
* @ hello_world is Free Software
* @ Released under GNU/GPL License : http://www.gnu.org/copyleft/gpl.html
* @version 1.0
**/
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
class menuHello_world {
function TEXT_MENU() {
mosMenuBar::startTable();
mosMenuBar::publish('publish');
mosMenuBar::unpublish('unpublish');
mosMenuBar::divider();
mosMenuBar::addNew('new');
mosMenuBar::editList('edit', 'Edit');
mosMenuBar::deleteList( ' ', 'delete', 'Remove' );
mosMenuBar::endTable();
}
function EDIT_MENU() {
mosMenuBar::startTable();
mosMenuBar::back();
mosMenuBar::save('save');
mosMenuBar::spacer();
mosMenuBar::endTable();
}
}
?>
class menuHello_world {
Sets the toolbar class
function TEXT_MENU() {
mosMenuBar::startTable();
mosMenuBar::publish('publish');
mosMenuBar::unpublish('unpublish');
mosMenuBar::divider();
mosMenuBar::addNew('new');
mosMenuBar::editList('edit', 'Edit');
mosMenuBar::deleteList( ' ', 'delete', 'Remove' );
mosMenuBar::endTable();
}
告诉mosMenuBar 在工h中输Z么内容,括号中小写的内容告诉admin.hello_world.php
执行哪个d?

希望怽看官眼睛q没有花Q?Q?q只是对lg的一个很单的介绍Q但是如果你打印本教E的话还是有16之长:-Q? 希望本教E能帮助你设计出更强大的MAMBOlgQ没准会收入MAMBO5.0版中哦)


*q里其实?7,因ؓ我重新排了一下版?


原文代码在我的机器中安装有许多问? 大家可下载我修改后的代码Ҏ源码, 仅供新手学习使用(共同学习.... )



蛮哥♂枫 2006-03-07 10:55 发表评论
]]>
վ֩ģ壺 | Ʊ| º| | ӽ| Ϣ| ͩ| ÷| | ۰| | | | | ̨| ɽ| Ұ| | ɳ| ³| ˮ| | ̩| ָ| Դ| | | | | | | | | | ں| | ׿| Ϸ| | | |