安装好sectionth后阴阳师辅助工具具不齐是怎么回事

glex 的BLOG
用户名:glex
文章数:114
评论数:52
访问量:253181
注册日期:
阅读量:5863
阅读量:12276
阅读量:358175
阅读量:1054591
[匿名]helloabc:
51CTO推荐博文
1,安装GCC开发工具
# Install software called by by VMware Tools
yum install gcc
2,安装内核文件
# Install kernel header files
yum install kernel-devel
3.检查内核文件的版本是否匹配,如果不匹配需要进行升级
# Check it matches the running kernel
uname -r             # running kernel
rpm -q kernel-devel  # installed kernel headers
4,第3不中如果不匹配,则需要升级内核文件,升级完后,重新启动系统
# It the two versions do not match, run
yum -y upgrade kernel kernel-devel
# then reboot (but only if they did not match).
5,查找内核文件的位置,安装VMware-tool工具时候需要(我装的时候,会自动查找到,不需要手工指定)
# Find out where the kernel headers are
ls -d /usr/src/kernels/$(uname -r)*/include
# You may need this later.
6,下载虚拟机工具安装包,即:VMware-tool安装包,并解压(具体就是在虚拟机工具栏上,点击&VM&-&&Install VMware Tools&,会出现安装包,选择*.gz的文件,解压到一个目录下就可以)
以下是命令行中具体实现方法,我是在图形界面下实现的
# If you already have VMwareTools-5.5.2-29772.tar.gz
on disk, SKIP THIS STEP!
# Download VMware-workstation-5.5.2-29772.tar.gz
# Extract the VMware Tools iso from it
tar --strip-components=3 -zxvf VMware-workstation-5.5.2-29772.tar.gz \
vmware-distrib/lib/isoimages/linux.iso
# Create a temporary mount point
mkdir /mnt/vmtools-temp
# Mount the image
mount -o loop linux.iso /mnt/vmtools-temp
# Copy VMware Tools from the mount
cp /mnt/vmtools-temp/VMwareTools-5.5.2-29772.tar.gz /tmp/
# Unmount the image and tidy up
umount /mnt/vmtools-temp
rmdir /mnt/vmtools-temp
rm linux.iso
# Unpack VMware Tools to a temporary directory
tar zxvf VMwareTools-5.5.2-29772.tar.gz
7.进入解压目标目录,执行以下代码,一路回车按下来
cd /tmp/vmware-tools-distrib/
./vmware-install.pl
8.直到该步骤,拷贝粘贴第5步的路径,然后一直按回车,直到选择屏幕分辨率。
What is the location of the directory of C header files that match your running
kernel? [/usr/src/kernels/2.6.18-1.2849.fc6-i686/include]
提示信息显示hgfs模块安装有问题,没关系,下一篇文章中解决。
9.到了该步骤,问你是否改变X-window的设置,选y,就可以改变分辨率。
Do you want to change your guest X resolution? (yes/no) [no] y
Please choose one of the following display sizes (1 - 13):
[1] &640x480&
[2]& &800x600&
Please enter a number between 1 and 13:
还不行呢,再跟着下边的走吧!
I keep several Linux distributions running on VMware Workstation due to my work. Unfortunately, due to recent changes in the Linux kernel, you cannot properly compile the vmhgfs driver on Fedora Core 6. Fortunately, I have a workaround until VMware releases a proper fix.
First, go to /usr/lib/vmware-tools/modules/source and unpack vmhgfs.tar like this:
******************ggggggggggg************************
tar -xf vmhgfs.tar
********************************************************
Now you should have a new directory called vmhgfs-only. You need to get the following patch to make it work:
vmhgfs-i_node-fix.patch()
To apply it, simply run:
patch -p1 & /wherever/you/saved/it/vmhgfs-i_node-fix.patch
This will patch vmhgfs-only/driver.c to conform with the kernel changes. Now you will have to repack it and reconfigure the VMware Tools. Simply run the following two commands:
tar -cf vmhgfs.tar vmhgfs-only
************************ggggggggggggggg*******************
run the command:
/usr/bin/vmware-config-tools.pl
**********************************************************
If all you want is to get the module compiled, you're all set. If you actually need to access a shared folder, then you should know that this workaround will not work while SELinux is enabled. If you want to use the files, you will have to disable SELinux by going to System -& Administration -& Security Level and Firewall. You will have to reboot, but after that, everything should work fine.
One more thing. If your host is Windows, you may notice that the files on the shared folders will appear as only accessible by root (they are in fact fully modifiable by everyone, but GNOME won't see it and this can be an annoyance.) If you want, the patch below will make all files appear with proper permissions (all permissions for everyone.) Apply it using the same steps used for the patch above.
vmhgfs-perm-fix.patch ()
Now,all the ok.
下面是两个patch文件的内容:
diff -Naur vmhgfs-only/driver.c vmhgfs-only-new/driver.c
--- vmhgfs-only/driver.c
14:25:52. -0300
+++ vmhgfs-only-new/driver.c
15:26:14. -0300
@@ -41,8 +41,8 @@
#define HGFS_SB_TO_COMMON(sb) ((HgfsSuperInfo *)(sb)-&s_fs_info)
-#define INODE_SET_II_P(inode, info) do { (inode)-&u.generic_ip = (info); } while (0)
-#define INODE_GET_II_P(inode) ((HgfsInodeInfo *)(inode)-&u.generic_ip)
+#define INODE_SET_II_P(inode, info) do { (inode)-&i_private = (info); } while (0)
+#define INODE_GET_II_P(inode) ((HgfsInodeInfo *)(inode)-&i_private)
* 2.5.x kernels support nanoseconds timestamps.
@@ -760,7 +760,6 @@
inode-&i_uid = 0; /* This is bogus, should be the mount owner. */
inode-&i_gid = 0; /* This is bogus, should be the mount owner. */
inode-&i_rdev = 0; /* Device nodes are not supported */
- inode-&i_blksize = HGFS_BLOCKSIZE;
inode-&i_blocks = (attr-&size + HGFS_BLOCKSIZE - 1) / HGFS_BLOCKSIZE;
inode-&i_size = attr-&
HGFS_SET_TIME(inode-&i_atime, attr-&accessTime);
--- vmhgfs-only/driver.c
15:26:14. -0300
+++ vmhgfs-only/driver.c-new
15:34:07. -0300
@@ -755,7 +755,7 @@
/* Set the access mode. */
inode-&i_mode &= ~S_IRWXUGO;
- inode-&i_mode |= (attr-&permissions && 6); /* Only applies to owner. */
+ inode-&i_mode |= attr-&permissions * 0111; /* Only applies to owner. */
inode-&i_nlink = 1; /* Bogus? */
inode-&i_uid = 0; /* This is bogus, should be the mount owner. */
inode-&i_gid = 0; /* This is bogus, should be the mount owner. */
最后修改xorg config设置,不然重启后会报X-WINDOWS出错。
进入/etc/X11/,用文本打开xorg.conf,加上以下几段:
1、Section &Monitor&
Identifier &vmware&
EndSection
Section &InputDevice&
Identifier &Mouse0&
Driver &vmmouse&
Option &Protocol& &Auto&
Option &Device& &/dev/input/mouse0&
EndSection
2、Section &Monitor&
Identifier &Monitor0&
ModelName &LCD Panel &
HorizSync 31.5 - 67.0
VertRefresh 50.0 - 75.0
Option &dpms&
EndSection
然后找到 含有&ServerLayout& 的section, 在Section跟EndSection之间加上以下一行。
InputDevice &Mouse0& &CorePointer&
――――――――――――――――――――――――――――――――-――――――――――――――――――――――
呵呵,仔细算一下吧,一般安装好系统的话,总是可以在网上找到更新包的,所以进行前面几步更新的话,你需要一个可以联网的fedora,由于是连接到外国的服务器,又由于没有迅雷可以用, 所以:gcc安装更新的话,有16M之多,kernel-devel安装的话有60M的文件要下载,这个在网络好的情况下也大概要折腾整个白天吧。安装完了,还要修改配置,才能正常使用!累啊。 我可受不了的哦。
fedora这么优秀的系统就是为了方便我们的学习,方便我们的使用,方便我们的操作啊!为什么要这么复杂呢!
现在在fedora下安装vmware tools就改用下面的方法吧:
********************************************************************************************************
第一步:为此客户机(GUEST OS)选择插入了此fedora系统的安装光盘的光驱。
第二步:启动此客户机,在图像模式下(图形模式比较方便,如果你喜欢在文本模式下操作只能说明你是高手哦)挂载光盘,打开/Media/disk/Fedora/RPM,也就是光盘里的fedora文件夹下的rpm文件夹,里面有kenel-devel-(版本号)-i586.RPM和一个i686的RPM文件,根据你的系统选择一个,安装就可以了。然后弹出光盘。(i386、i586、i686指的是适用于intel i386、 i586、i686 兼容指令集的微处理器。一般来说,等级愈高的机器可接受较低等级的rpm文件。你可以透过/proc/cpuinfo这个档案查询你的CPU等级。)
这一步是核心,这一步就代替了老方法的前7部,就给你省了整个白天的时间。
第三步:选择在虚拟机的菜单vm下选择install vmware tools,在客户机fedora里面挂载光盘。解压VMwareTools-(版本号).tar.gz的文件到/tmp中。以上的步骤在图像模式下很简单,文本模式下的命令方式就不讲了。
第四步:在fedora系统下按ctrl+alt+F1进入虚拟平台1,以root帐户登录,运行一下命令:/tmp/vmware-tools-distrib/vmware-install.pl
回车就开始安装了,如果找不到这个文件则用cd和ls查看刚才解压的目录下的PL文件的文件名。
第五步:一路回车,选择默认的即可。 特别说明:在
What is the location of the directory of C header files that match your running
这一步时,系统会给你自动选择正确的文件夹位置,不用改了,直接回车。一般是/lib/modules/(版本号)/build/include
第六步:在分辨率选择界面按数字选择分辨率。所以操作都是自动的,一直到安装完成,回到$的输入提示符下。
第七步:输入reboot。成功
*********************************************************************************************************
现在,你就可以自由的将鼠标移进移出虚拟机了,共享文件夹仍然在/mnt/hgfs下面,访问windows的共享文件夹非常快。感觉真的很爽啊。
然后可以把tmp下解压出来的文件夹给删了,给自己的硬盘省点空间嘛,本来fedora就够大的了。
在终端下使用 $vmware-toolbox 打开vmware tools配置对话框。
光盘里的kernel-devel只有几M,比你用迅雷下源码40多M也小多了吧,一切都是那么的简单,原理呢,也就省略 了。
了这篇文章
类别:未分类┆阅读(0)┆评论(0)[joomla安装]joomla_ok_joomla安装-牛宝宝文章网
[joomla安装]joomla_ok joomla安装
Joomla添加问题描述:文章的分页和引言的实现步骤:1.文章创建2.在文章中作为引言的部分后面点击编辑框下端的“引言与正文分离(阅读全文按钮)”就会在需要作为引言的文字下面添加一行红色的虚线3.在需要文章中需要分页的文字后面点击编辑框下方的分页符。即可在文字下方加入一行灰色的虚线,添加分页符时会弹出对话框让你填入该页的关键字或者题目(可填可不填,填好后会在文章中浏览的导航菜单看到你加入的该页面的关键字)4.完成后,点击保存即可Joomla建站日程表备注:上午3小时,下午5小时如何创建一个Joomla组件如何创建一个MVC模式的Joomla组件(一)Joomla 1.5的新框架为开发者解除了束缚,代码彻底的修改和整理过了。本文给出了采用新框架的开发过程。我们将开发一个hello world的组件,接下来的教程中,在这个简单框架的基础上将展现MVC设计模式的力量。MVC模式尽管这个组件非常简单,可是随着添加新的功能或者自定义界面,代码可以非常复杂。 MVC就是数据表示和商业逻辑分开的软件设计模式,这样的前提就是商业逻辑在一起,而界面和用户交互能够被自定义或者修改而不会改变盛业逻辑的程序。一个MV C自建有三个主要的部分,这里做了简要说明,更加详细的解释请看本教程给出的参考连接诶。Modelmodel封装了应用的数据,同时提供了管理和操作数据的功能。在例子中 model 包含了add, remove and update数据库中的greeting信息,同时包含了从数据库返回greeting的list. 通常来说数据的访问英爱封装在model中,这样加入系统从一个文件数据系统中迁移到一个数据库中,那么仅仅需要修改model,而view和controller都不必修改。Viewview 是组件的一部分,用来以一种适合用户交互的方式来组织和展示数据。对于web应用,通常view就是html页面,view从model获得数据,并传递给模板。view不做任何的数据修改,他仅仅是展示从model获得的数据。Controllercontroller负责用户的操作,对于一个web应用,一个用户的操作就是页面的请求,controller根据请求决定调用合适model并传递数据到view。Joomla! MVCJoomla实现了MVC模式,主要包括以下三个类 JModel, JView,JController. 更详细的信息请参考api文档.如何创建一个MVC模式的Joomla组件(二)创建组件对于这个简单的组件,只需5个文件:hello.php - 组件的入口文件controller.php - controller基类views/hello/view.html.php - 返回数据,传递给模板views/hello/tmpl/default.php - 模板文件hello.xml - 组件安装文件创建入口文件Joomla!总是有一个单一的如楼,比如对于站点应用是/index.php,而对于管理应用是/administrator/index.php,根据URL或者POST数据中option参数,来决定载入必要的组件。我们开发的这个组件的入口:index.php?option=com_hello&view=hello这就会载入我们的主文件,也就是组件的入口文件 components/com_hello/hello.php. 以下的代码对于所有的组件是相当典型的:&?php/*** @package
Joomla.Tutorials* @subpackage Components* components/com_hello/hello.php* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
* @license
GNU/GPL*/// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );// Require the base controllerrequire_once( JPATH_COMPONENT.DS.'controller.php' );// Require specific controller if requestedif($controller = JRequest::getWord('controller')) {$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';if (file_exists($path)) {require_once $} else {$controller = '';}}// Create the controller$classname
= 'HelloController'.$$controller
= new $classname( );// Perform the Request task$controller-&execute( JRequest::getVar( 'task' ) );// Redirect if set by the controller$controller-&redirect();?&第一句声明是一个安全检查。JPATH_COMPONENT 当前组件的绝对路径, 对于这个组件是 components/com_hello.DS 是系统目录分隔符:
‘/’ 或 ‘\’,由系统自动设置,从而开发者不必担心系统和版本的问题。在controller载入后,要检查是否有特别的controller需要载入。本例中没有,但是我们保留以备后用。JRequest::getVar() 是获取get或post的数据. 如果url: index.php?option=com_hello&controller=controller_name,JRequest::getVar(’controller’)就可以返回controller的名字;controller命名规则是‘{Componentname}{Controller}{Controllername}’创建了controller后, 就要执行任务,url: index.php?option=com_hello&task=sometask. 如果没有指定task,那么就执行display,这时view决定显示什么。controller可以转向, 比如保存任务完成后. 最后一行程序就是监测转向.如何创建一个MVC模式的Joomla组件(三)创建 Controller组件例子只有一个任务 - greet the world. 因此controller非常简单. 不需要数据操作,所做的只是决定调用那个合适的view. 我们只有一个方法 display().以下是源代码:&?php/*** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
* @license
GNU/GPL*/// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );jimport('ponent.controller');/*** Hello World Component Controller* * @package
Joomla.Tutorials * @subpackage Components */class HelloController extends JController{/*** Method to display the view** @access
public*/function display(){parent::display();}}?&JController 构造函数注册 display() 任务,除非用 registerDefaultTask() 指定默认任务,否则dislpaly作为默认的任务。事实上这里调用display也不是必须的,因为display仅仅是调用父类的display。 JController::display() 确定合适的view和模板,并且载入他们。例子组件中,我们只有一个view,hello,一个模板default.如何创建一个MVC模式的Joomla组件(四)创建 Viewview的工作很简单,就是获取数据,用assignRef传递给模板。view 代码如下:&?php/*** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
* @license
GNU/GPL*/// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );jimport( 'ponent.view');/*** HTML View class for the HelloWorld Component** @package
HelloWorld*/class HelloViewHello extends JView{function display($tpl = null){$greeting = "Hello World!";$this-&assignRef( 'greeting', $greeting );parent::display($tpl);}}?&如何创建一个MVC模式的Joomla组件(五) 创建模板Joomla! 模板使用用来以特定方式布置从view获取数据的php文件 在模板中可以 用$this→{propertyname}获取view通过assignref传递的数据。例子中模板非常简单,以下是代码:&?php // no direct accessdefined('_JEXEC') or die('Restricted access'); ?&&h1&&?php echo $this-& ?&&/h1&如何创建一个MVC模式的组件(六) 创建 hello.xml打包 - 创建 hello.xml可以通过上传文件,然后修改数据表来安装组件。更有效的方式是创建一个安装包,让Joomla installer帮你做安装。 这个安装文件包含以下内容:组件的基本信息要拷贝的文件执行安装和卸载的php文件.sql语句xml文件格式如下:&?xml version="1.0" encoding="utf-8"?&&!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/component-install.dtd"& &install type="component" version="1.5.0"&&name&Hello&/name&&!-- The following elements are optional and free of formatting conttraints --&&creationDate&&/creationDate& &author&John Doe&/author& &authorEmail& john.doe@example.org&/authorEmail& &authorUrl&http://www.niubb./authorUrl&&copyright&Copyright Info&/copyright&&license&License Info&/license&&!--
The version string is recorded in the components table --&&version&Component Version String&/version&&!-- The description is optional and defaults to the name --&&description&Description of the component ...&/description&&!-- Site Main File Copy Section --&&!-- Note the folder attribute: This attribute describes the folderto copy FROM in the package to install therefore files copiedin this section are copied from /site/ in the package --&&files folder="site"&&filename&index.html&/filename&&filename&hello.php&/filename&&filename&controller.php&/filename&&filename&views/index.html&/filename&&filename&views/hello/index.html&/filename&&filename&views/hello/view.html.php&/filename&&filename&views/hello/tmpl/index.html&/filename&&filename&views/hello/tmpl/default.php&/filename&&/files&&administration&&!-- Administration Menu Section --&&menu&Hello World!&/menu&&!-- Administration Main File Copy Section --&&files folder="admin"&&filename&index.html&/filename&&filename&admin.hello.php&/filename&&/files&&/administration&&/install&你可能注意到了文件index.html,文件主要是浏览目录的时候显示这个文件,而不是显示目录下的文件结构。这个文件仅仅包含一行:&html&&body bgcolor="#FFFFFF"&&/body&&/html&就是一个空白页面另外一个文件是 admin.hello.php file,这是管理组件的入口,目前我们没有这部分内容,所以他的内容和index.html内容相同如何创建一个MVC模式的组件(七) 添加model添加一个 Model序言在上一文章中,我们做了一个Joomla 1.5 MVC模式的hello world 组件。在例子中,greeting是直接写在view中的,这并不完全遵守MVC的原则,按照MVC的要求, view仅仅是展示数据而不是包含数据。现在,我们来展示如何将数据迁移到Model中。接下来的例子中,你可以看到MVC设计模式的强大和灵活性。创建Model正如其名,model这个类是代表一些实体的。例子中,这个model代表 'hello'或者一个greeting。model的命名约定是 {component namne}{Model}{model name},我们的例子中就是HelloModelHello目前为止,hello model只有一个行为,就是返回greeting。因此只有一个方法,getGreeting(),这个方法仅仅返回字串‘Hello, World!’.以下是model的代码:&?php/*** Hello Model for Hello World Component** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
* @license
GNU/GPL*/// Check to ensure this file is included in Joomla!defined('_JEXEC') or die();jimport( 'ponent.model' );/*** Hello Model** @package
Joomla.Tutorials* @subpackage Components*/class HelloModelHello extends JModel{/*** Gets the greeting * @return string The greeting to be displayed to the user */ function getGreeting(){return 'Hello, World!';}}先来看jimport( 'ponent.model' );这一行,Jimport函数的作用是载入组件必要的文件。,也就是载入了/libraries/joomla/application/component/model.php,所有的加载文件都是相对于libraries目录。这个文件包含了JModel类的定义。既然已经创建了model,我们必须修改view,从而view能从model获取数据。 使用modelJoomla! 自动调用与view相同名称的model,并推入view中. 因为view的名字是‘Hello’, 所以这个model会自动被加载.我们所要做的就是用JView::getModel()返回数据.前例中:$greeting = "Hello World!";现在我们修改为如下代码:$model =& $this-&getModel();$greeting = $model-&getGreeting();完整的view代码如下:&?php/*** Hello View for Hello World Component** @package
Joomla.Tutorials * @subpackage Components * @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/ * @license
GNU/GPL*/// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );jimport( 'ponent.view');/*** HTML View class for the HelloWorld Component** @package
Joomla.Tutorials* @subpackage Components*/class HelloViewHello extends JView{function display($tpl = null){$model =& $this-&getModel();$greeting = $model-&getGreeting();$this-&assignRef( 'greeting', $greeting );parent::display($tpl);}}?&添加文件到安装包中。我们要做就是把这个hello.php加入在xml相应部分&filename&models/hello.php&/filename&新的hello.xml完整清单如下:&?xml version="1.0" encoding="utf-8"?&&!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/component-install.dtd"& &install type="component" version="1.5.0"&&name&Hello&/name&&!-- The following elements are optional and free of formatting conttraints --&
&creationDate&&/creationDate&&author&John Doe&/author& &authorEmail& john.doe@example.org&/authorEmail& &authorUrl&http://www.niubb./authorUrl& &copyright&Copyright Info&/copyright&&license&License Info&/license&&!--
The version string is recorded in the components table --& &version&Component Version String&/version& &!-- The description is optional and defaults to the name --& &description&Description of the component ...&/description&&!-- Site Main File Copy Section --&&files folder="site"&&filename&index.html&/filename&&filename&hello.php&/filename&&filename&controller.php&/filename&&filename&views/index.html&/filename&&filename&views/hello/index.html&/filename&&filename&views/hello/view.html.php&/filename&&filename&views/hello/tmpl/index.html&/filename&&filename&views/hello/tmpl/default.php&/filename&&filename&models/index.html&/filename&&filename&models/hello.php&/filename&&/files&&administration&&!-- Administration Menu Section --&&menu&Hello World!&/menu&&!-- Administration Main File Copy Section --&&!-- Note the folder attribute: This attribute describes the folderto copy FROM in the package to install therefore files copiedin this section are copied from /admin/ in the package --&&files folder="admin"&&!-- Site Main File Copy Section --&&filename&index.html&/filename&&filename&admin.hello.php&/filename&&/files&&/administration&&/install&如何创建一个MVC模式的Joomla组件教程(八) 使用数据库 上序言前两个例子展示了如何创建简单的MVC组件,在第二个例子中view获取从model中返回的数据。本教程中,我们继续关注model,我们将直接从数据库获得数据,而不是直接写在model中。我们将演示如何利用JDatbase从数据库中取得数据取得数据第二个例子中只有一个方法getGreeting(),这个方法所做的仅仅是返回写在代码中的greeting.稍后将演示如何创建sql文件,并加入到xml安装文件中,从而在安装的时候自动创建数据表,加入初始的样板数据。现在我们将演示的是用什么代码替换就可以从数据库获得合适的数据。首先要获得数据库的引用,你这样做就可以了得到了$db =& JFactory::getDBO();JFactory 是一个静态类,通过它可以取得很多的实例(请参见源代码解析,JFactory类). getDBO就是 get DataBase Object 的缩写, 很容易记住吧接下来我们取回数据吧,这需要两步,一是存储query,一是载入结果以下是getGreeting的代码function getGreeting(){$db =& JFactory::getDBO();$query = 'SELECT greeting FROM #__hello';$db-&setQuery( $query );$greeting = $db-&loadResult();return $}hello是我们以后要创建的表名,greeting是存储数据的字段名。如果你不熟悉sql,最好找个教程手册速成一下,可以在w3schools找到这样的教程。$db-&loadResult()执行查询,返回结果集中第一行的第一个字段. .创建sql文件joomla installer支持执行sql,这些sql语句都保存在标准的文本文件中。在安装文件有三个语句,一个如果表已经存在那么就删除,第二个是创建表,第三是插入样例数据。 以下是全部文本:DROP TABLE IF EXISTS `#__hello`;CREATE TABLE `#__hello` (`id` int(11) NOT NULL auto_increment,`greeting` varchar(25) NOT NULL,PRIMARY KEY
(`id`)) ENGINE=MyISAM AUTO_INCREMENT DEFAULT CHARSET=utf8;INSERT INTO `#__hello` (`greeting`) VALUES ('Hello, World!'),('Bonjour, Monde!'),('Ciao, Mondo!');如何创建一个MVC模式的Joomla组件教程(九) 使用数据库下你可能看到了表的前缀非常奇怪。Joomla将替换这个前缀,用安装时候指定的内容。对于通常的安装,这个表名将是jos_hello,这样可以多个安装使用一个数据库,并且能够避免表名冲突。表中有两个字段,一是id,是主键,一是greeting.以上内容保存在 install.utf.sql.创建卸载sql文件尽管我们希望永远不必卸载组件,然而卸载也是重要的。Joomla将自动找到需要删除的文件和目录,可是必须要将删除表的sql语句写在安装文件中。语句如下:DROP TABLE IF EXISTS `#__hello`;保存在 uninstall.utf.sql中.新的安装文件如下:&?xml version="1.0" encoding="utf-8"?&&!DOCTYPE install SYSTEM "http://dev.joomla.org/xml/1.5/component-install.dtd"&&install type="component" version="1.5.0"&&name&Hello&/name& &!-- The following elements are optional and free of formatting conttraints --& &creationDate&&/creationDate& &author&John Doe&/author&&authorEmail& john.doe@example.org&/authorEmail&&authorUrl&http://www.niubb./authorUrl&&copyright&Copyright Info&/copyright&&license&License Info&/license&&!--
The version string is recorded in the components table --&&version&Component Version String&/version&&!-- The description is optional and defaults to the name --&&description&Description of the component ...&/description&&!-- Site Main File Copy Section --&&files folder="site"&&filename&index.html&/filename&&filename&hello.php&/filename&&filename&controller.php&/filename&&filename&views/index.html&/filename&&filename&views/hello/index.html&/filename&&filename&views/hello/view.html.php&/filename& &filename&views/hello/tmpl/index.html&/filename& &filename&views/hello/tmpl/default.php&/filename& &filename&models/hello.php&/filename&&/files&&install&&sql&&file charset="utf8" driver="mysql"&install.sql&/file&&/sql&&/install&&uninstall&&sql&&file charset="utf8" driver="mysql"&uninstall.sql&/file&&/sql&&/uninstall&&administration&&!-- Administration Menu Section --&&menu&Hello World!&/menu&&!-- Administration Main File Copy Section --&&!-- Note the folder attribute: This attribute describes the folderto copy FROM in the package to install therefore files copiedin this section are copied from /admin/ in the package --&&files folder="admin"&&!-- Site Main File Copy Section --&&filename&index.html&/filename&&filename&admin.hello.php&/filename&&filename&install.sql&/filename&&filename&uninstall.sql&/filename&&/files&&/administration&&/install&在install和uninstall部分,file标签中指定了charset和driver,目前唯一合法的charset是utf-8,如果想在非utf8数据库创建表,可以忽略这个属性。driver属性目前只能是mysql,将来Joomla可能支持更多数据库。如何创建一个MVC模式的Joomla组件教程(十) - 创建管理员界面序言前三个例子我们开发了一个从数据库中获取数据的MVC组件。可是除了手工添加数据或者使用其他工具外,我们没有办法添加数据。本教程中,我们将开发一个管理部分从而能够管理数据。创建基本框架后台管理基本框架与前台站点部分基本相同。管理部分的主入口是 admin.hello.php. 这个文件与我们在前他部分使用的hello.php是一样的,除了controller改为 HellosController.默认的controller也是controller.php,并且除了controller名字是HellosController以外,其他与前台部分的controller.php都一样,还有不同就是将默认调用hellos view,这个view显示greetings的列表以下admin.hello.php代码清单:&?php/*** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:components/
* @license
GNU/GPL*/// no direct accessdefined( '_JEXEC' ) or die( 'Restricted access' );// Require the base controllerrequire_once( JPATH_COMPONENT.DS.'controller.php' );// Require specific controller if requestedif($controller = JRequest::getWord('controller')) {$path = JPATH_COMPONENT.DS.'controllers'.DS.$controller.'.php';if (file_exists($path)) {require_once $} else {$controller = '';}}// Create the controller$classname
= 'HellosController'.$$controller
= new $classname( );// Perform the Request task$controller-&execute( JRequest::getVar( 'task' ) );// Redirect if set by the controller$controller-&redirect();?&view和model都是以hellos开头的,下面将介绍model和view.如何创建一个MVC模式的Joomla组件教程(十一) - 创建管理员界面Hellos ModelHellos ModelHellos Model非常简单,我们需要的是从数据库返回hellos列表,这通过getData()方法实现。 还有一个_getList()的保护方法,这个方法用来简化从数据库返回数据的任务,我们只是简单的传递query并且返回记录列表。也许以后某个时候,我们在另一个方法中使用这个查询,因而我们创建了一个私有方法 _buildQuery() ,这个方法返回query,并且传递给_getList(). 这样可以集中在一处来修改查询语句。getData() 和 _buildQuery() 方法是必须需要的:_buildQuery() 仅仅是返回语句,代码如下:/*** Returns the query* @return string The query to be used to retrieve the rows from the database*/function _buildQuery(){$query = ' SELECT * '. ' FROM #__hello ';return $}getData() 将用这个sql从数据库返回数据. 也许我们需要两次获取同样数据,重复运行查询是非常浪费的,因而,我们保存结果在一个保护属性_data中,这样只需查询一次就可以了。以下是 getData() 方法:/*** Retrieves the hello data* @return array Array of objects containing the data from the database*/function getData(){// Lets load the data if it doesn't already existif (empty( $this-&_data )){$query = $this-&_buildQuery();$this-&_data = $this-&_getList( $query );}return $this-&_}完整model代码如下(models/hellos.php):&?php/*** Hellos Model for Hello World Component** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:components/
* @license
GNU/GPL*/// Check to ensure this file is included in Joomla!defined('_JEXEC') or die();jimport( 'ponent.model' );/*** Hello Model** @package
Joomla.Tutorials* @subpackage Components*/class HellosModelHellos extends JModel{/*** Hellos data array** @var array*/var $_/*** Returns the query* @return string The query to be used to retrieve the rows from the database*/function _buildQuery(){$query = ' SELECT * '. ' FROM #__hello ';return $}/*** Retrieves the hello data* @return array Array of objects containing the data from the database*/function getData(){// Lets load the data if it doesn't already existif (empty( $this-&_data )){$query = $this-&_buildQuery();$this-&_data = $this-&_getList( $query );}return $this-&_}}如何创建一个MVC模式的Joomla组件教程(十二) - 创建管理员界面Hellos viewHellos View现在model已经返回了数据,那么就需要view来显示数据。view与前台的view也相似 与前台一样,这里的model也是自动初始化的。view主要有三行程序,一是得到model返回的数据,二是传递数据给模板,三是调用display方法,显示输出。以下是 views/hellos/view.html.php. 代码清单:&?php/*** Hellos View for Hello World Component** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:components/
* @license
GNU/GPL*/// Check to ensure this file is included in Joomla!defined('_JEXEC') or die();jimport( 'ponent.view' );/*** Hellos View** @package
Joomla.Tutorials* @subpackage Components*/class HellosViewHellos extends JView{/*** Hellos view display method* @return void**/function display($tpl = null){JToolBarHelper::title( JText::_( 'Hello Manager' ), 'generic.png' );JToolBarHelper::deleteList();JToolBarHelper::editListX();JToolBarHelper::addNewX();// Get data from the model$items =& $this-&get( 'Data');$this-&assignRef( 'items', $items );parent::display($tpl);}}如何创建一个MVC模式的Joomla组件教程(十三) - 创建管理员界面Hellos TemplateHellos Template模板获取view传递的数据,并生成输出。我们用一个表格显示输出,尽管前台的模板非常简单,可是后台的管理复杂一些从而能处理数据。这是 views/hellos/tmpl/default.php的代码清单 :&?php defined('_JEXEC') or die('Restricted access'); ?&&form action="index.php" method="post" name="adminForm"&&div id="editcell"&&table class="adminlist"&&thead&&tr&&th width="5"&&?php echo JText::_( 'ID' ); ?&&/th&&th&&?php echo JText::_( 'Greeting' ); ?&&/th&&/tr&&/thead&&?php$k = 0;for ($i=0, $n=count( $this-&items ); $i & $n; $i++){$row =& $this-&items[$i];?&&tr class="&?php echo "row$k"; ?&"&&td&&?php echo $row-& ?&&/td&&td&&?php echo $row-& ?&&/td&&/tr&&?php$k = 1 - $k;}?&&/table&&/div&&input type="hidden" name="option" value="com_hello" /&&input type="hidden" name="task" value="" /&&input type="hidden" name="boxchecked" value="0" /&&input type="hidden" name="controller" value="hello" /&&/form&你看到我们的输出用一个form包含,现在并不是必须的,但是以后有用处。以下是新增的5个文件,你可以把这些文件添加到xml中,并试试。 admin.hello.phpcontroller.phpmodels/hellos.phpviews/hellos/view.html.phpviews/hellos/tmpl/default.php如何创建一个MVC模式的Joomla组件教程(十四) - 创建管理员界面 增加管理功能直到目前为止,管理界面没有什么实际用户,除了显示数据。我们需要增加一些按钮和链接,从而能执行管理功能。The Toolbartoolbar是Joomla组件管理控制面板的顶部。这个组件同样也需要一个,在Joomla中这是非常简单的。现在来增加按钮来处理添加,修改,删除记录,还需要增加一个toolbar上的标题。以下的代码就可以添加按钮了,为添加按钮,我们使用了Joomla的 JToolBarHelper 静态类。 JToolBarHelper::title(
JText::_( 'Hello Manager' ), 'generic.png' );JToolBarHelper::deleteList();JToolBarHelper::editListX();JToolBarHelper::addNewX();以上的三个方法创建了三个按钮,deleteList()有三个可选参数,一是提示用户确认删除的字符串,二是请求中需要发送的task,默认是remove,三是显示在删除按钮下边的文字。 editListX()和addNewX()方法有两个参数,一是task(默认的是edit和add),二是按钮下显示的文字。请注意JText::_ 方法,这是一个处理多语言的方便的函数,这个寻找你语言文件中对应的字符串,并返回转换后的字符串,如果没有找到字符串,将直接返回传递给JText::_的字符串。如果你要翻译你的组件,你要做的工作就是创建一个语言文件,这个语言文件包含字符串的map集合。复选框和链接按钮现在有了,可是修改和删除是要针对已存在的记录。但是需要用户选择那些记录需要进行这些操作。因此,我们在模板中添加了复选框。我们在表格中添加额外的一列。在这一个列的表头中,我们添加了一个复选框,这个复选框用来选中和清除所有复选框的装提案。 &th width="20"&&input type="checkbox"count( $this-&items ); ?&);" /&&/th& name="toggle" value="" onclick="checkAll(&?php echoJoomla的Javascript包含了一个函数checkAll,这里我们使用了这个函数。接下来需要给每一行添加一个复选框,Joomla的JHTML类有一个函数JHTML::_(),以下就是代码:$checked
= JHTML::_( 'grid.id', $i, $row-&id );$row =& $this-&items[$i];&td&&?php echo $ ?&&/td&需要需要修改记录的时候,先选中复选框,然后再点击上边的edit按钮,这样的操作比较繁琐,因此,我们要添加一个链接,直接进入编辑界面。以下是代码:$link = JRoute::_( 'index.php?option=com_hello&controller=hello&task=edit&cid[]='. $row-&id ); &td&&a href="/&?php echo $ ?&"&&?php echo $row-& ?&&/a&&/td&值得注意的是,链接中的controller指向hello controller,这个controller处理数据操作。 在返回看以下form,其中有四个隐藏的输入域。第一个是option,这是是进入component必须的,第二是task,对应这toolbar上的按钮操作,如果没有这个字段,javascript将报错,从而操作失败。第三个字段是boxchecked,主要是有多少复选框被选中,edit和delete按钮操作会检查这个字段不小于0,最后一个是controller,这个输入决定采用那个controller. 以下是模板 default.php 的代码清单:&?php defined('_JEXEC') or die('Restricted access'); ?&&form action="index.php" method="post" name="adminForm"&&div id="editcell"&&table class="adminlist"&&thead&&tr&&th width="5"&&?php echo JText::_( 'ID' ); ?&&/th&&th&&?php echo JText::_( 'Greeting' ); ?&&/th&&/tr&&/thead&&?php$k = 0;for ($i=0, $n=count( $this-&items ); $i & $n; $i++){$row =& $this-&items[$i];?&&tr class="&?php echo "row$k"; ?&"&&td&&?php echo $row-& ?&&/td&&td&&?php echo $row-& ?&&/td&&/tr&&?php$k = 1 - $k;}?&&/table&&/div&&input type="hidden" name="option" value="com_hello" /&&input type="hidden" name="task" value="" /&&input type="hidden" name="boxchecked" value="0" /&&input type="hidden" name="controller" value="hello" /&&/form&现在hellos view完成了,去试试吧。如何创建一个MVC模式的Joomla组件教程(十五) - 创建管理员界面 增加编辑功能 上现在hellos view完成了,现在需要完成hello view和 model, 他们实际复杂数据处理工作。 Hello Controller默认的controller仅仅是展示数据,现在需要controller能处理从hellos view发出的添加,删除,修改任务,添加和编辑本质是相同的任务,他们都是显示给用户一个form来做greeting编辑,不同的是添加是一个空的form,而edit有数据,因此我们把add任务映射给edit钩子函数。下面的构造器中做了这个操作/*** constructor (registers additional tasks to methods)* @return void*/function __construct(){parent::__construct();// Register Extra tasks$this-&registerTask( 'add'
'edit' );}JController::registerTask是将add映射到edit钩子函数上。现在我们处理编辑任务,controller处理edit任务相当简单,所要做的仅仅设指定view和模板,这里在编辑的同事要禁用主菜单,从而用户不能离开而不保存数据。edit 任务的钩子函数清单:/*** display the edit form* @return void*/function edit(){JRequest::setVar( 'view', 'hello' );JRequest::setVar( 'layout', 'form'
);JRequest::setVar('hidemainmenu', 1);parent::display();}Hello ViewHello view 显示一个表单允许用户编辑. display要完成下面一些简单任务:从model获取数据创建toolbar给模板template传递数据调用display()填充模板因为要处理编辑和添加,所以稍稍有点复杂。在toolbar中需要用户知道是否在添加或编辑,从而我们决定触发那个任务。因为我们已经从model获取了数据,因而可以推断是那个任务被触发,如果是编辑,那么id字段是有数据的,否则,这个字段就是空的,由此可以确定是添加还是编辑记录。 在toolbar中还添加了两个按钮,保存和取消。We will add two buttons to the toolbar: save and cancel. Though the functionality will be the same, we want to display different buttons depending on whether it is a new or existing record. If it is a new record, we will display cancel. If it already exists, we will display close.display 方法的清单如下:/*** display method of Hello view* @return void**/function display($tpl = null){//get the hello$hello
=& $this-&get('Data');$isNew
= ($hello-&id & 1);$text = $isNew ? JText::_( 'New' ) : JText::_( 'Edit' );JToolBarHelper::title(
JText::_( 'Hello' ).': &small&&small&[ ' . $text.' ]&/small&&/small&' );
JToolBarHelper::save();if ($isNew)
{JToolBarHelper::cancel();} else {// for existing items the button is renamed `close`JToolBarHelper::cancel( 'cancel', 'Close' );}$this-&assignRef('hello', $hello);parent::display($tpl);}如何创建一个MVC模式的Joomla组件教程(十六) - 创建管理员界面 增加编辑功能 下Hello Model现在我们来创建model.model有两个属性 _id and _data. _id存贮id,_data存储greeting数据.构造器中首先从request中取得id/*** Constructor that retrieves the ID from the request** @access
public* @return
void*/function __construct(){parent::__construct();$array = JRequest::getVar('cid',
0, '', 'array');$this-&setId((int)$array[0]);}JRequest::getVar() 方法用来从request中获取数据。第一个参数是form变量的名称,第二个参数是参数默认值,第三个参数he name of the hash to retrieve the value from,第四个是数据类型。构造器将取得cid数组中的第一个值并赋给id.setId()被用来设置id,如果id变化了,那么对应的data也应该变化,否则就出错了,因此当我们设置id的值的时候,清空data的数据。/*** Method to set the hello identifier** @access
public* @param
int Hello identifier* @return
void*/function setId($id){// Set id and wipe data$this-&_id
= $$this-&_data
=}最后还要有getData()来获取数据,getData检查 data是否已经设置,如果已经设置,仅仅返回,如果没有,就从数据库载入。/*** Method to get a hello* @return object with data*/function &getData(){// Load the dataif (empty( $this-&_data )) {$query = ' SELECT * FROM #__hello '.'
WHERE id = '.$this-&_$this-&_db-&setQuery( $query );$this-&_data = $this-&_db-&loadObject();}if (!$this-&_data) {$this-&_data = new stdClass();$this-&_data-&id = 0;$this-&_data-&greeting =}return $this-&_}表单 Form以下是表单的代码清单:&?php defined('_JEXEC') or die('Restricted access'); ?&&form action="index.php" method="post" name="adminForm" id="adminForm"&&div class="col100"&&fieldset class="adminform"&&legend&&?php echo JText::_( 'Details' ); ?&&/legend&&table class="admintable"&&tr&&td width="100" align="right" class="key"&&label for="greeting"&&?php echo JText::_( 'Greeting' ); ?&:&/label&&/td&&td&&input class="text_area" type="text" name="greeting"size="32" maxlength="250" value="&?php echo $this-&hello-&?&" /&&/td&&/tr&&/table&&/fieldset&&/div&&div class="clr"&&/div&&input type="hidden" name="option" value="com_hello" /&&input type="hidden" name="id" value="&?php echo $this-&hello-& ?&" /&&input type="hidden" name="task" value="" /&&input type="hidden" name="controller" value="hello" /&&/form&注意,有一个id隐藏项,我们不应该改变id,而仅仅是传递。 id="greeting"如何创建一个MVC模式的Joomla组件教程(十七) - 创建管理员界面 保存记录功能上到目前为止,我们仅处理了编辑和添加,还有保存,删除,取消没处理,现在要写执行这些任务的代码。保存记录理论上我们需要实现保存数据的功能,可能需要一些逻辑分支处理不同情况。幸运的是joomla接管了很多这样的工作。JTable类实现了数据操作功能,而不必关心实际的sql语句,并且把数据从form加入数据库更简单了。创建 Table 类JTable是一个抽象类,对于指定的数据库表我们要从JTable继承类,这里我们只需要创建一个类,添加字段作为shuxing ,重写constructor指定表名和主键就可以了以下是JTable的代码清单:&?php/*** Hello World table class** @package
Joomla.Tutorials* @subpackage Components* @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:components/
* @license
GNU/GPL*/// no direct accessdefined('_JEXEC') or die('Restricted access');/*** Hello Table class** @package
Joomla.Tutorials* @subpackage Components*/class TableHello extends JTable{/*** Primary Key** @var int*/var $id =/*** @var string*/var $greeting =/*** Constructor** @param object Database connector object*/function TableHello( &$db ) {parent::__construct('#__hello', 'id', $db);}}?&这里定义了id 和greeting,构造器中指定了表名hello和主键id如何创建一个MVC模式的Joomla组件教程(十八) - 创建管理员界面 保存记录功能下在model中实现数据操作现在添加一个store方法用来保存数据,store要绑定form传递的数据到TableHello对象,检查数据格式是否正确,保存数据。store方法代码如下:/*** Method to store a record** @access
public* @return
True on success*/function store(){$row =& $this-&getTable();$data = JRequest::get( 'post' );// Bind the form fields to the hello tableif (!$row-&bind($data)) {$this-&setError($this-&_db-&getErrorMsg());}// Make sure the hello record is validif (!$row-&check()) {$this-&setError($this-&_db-&getErrorMsg());}// Store the web link table to the databaseif (!$row-&store()) {$this-&setError($this-&_db-&getErrorMsg());}}第一行获取了JTable类实例,如果正确命名了名字,我们不必指定名字,Jmodel类自动找到合适的Jtable,我们创建了一个tables目录,并将JTable 命名为TableHello保存在 hello.php文件中,遵循这样的约定,就可以自动创建对象。第二行我们返回form的数据。JRequest做的非常简单,本例中,我们获取了所有post的变量,这些变量是以数组方式返回的。其余的非常简单了- bind, check and store. bind() 拷贝form的相应变量到JTable中. 本例中id和greeting赋值到TableHello对象中.check() 执行数据验证. 在JTable() class, 这个方法仅仅是简单返回true. 尽管现在没有实际用处,但是以后check可以做验证。store()方法保存数据到数据库中,如果id为0,将创建一个新目录,否则更新记录。添加controller任务现在来添加任务,任务的名称是save以下是代码清单:/*** save a record (and redirect to main page)* @return void*/function save(){$model = $this-&getModel('hello');if ($model-&store()) {$msg = JText::_( 'Greeting Saved!' );} else {$msg = JText::_( 'Error Saving Greeting' );}// Check the table in so it can be edited.... we are done with it anyway$link = 'index.php?option=com_hello';$this-&setRedirect($link, $msg);}我们所要做的是取得model,调用store方法,然后用 setRedirect(),返回greetings的列表页面,同事返回一个信息,显示在页面的顶部。如何创建一个MVC模式的Joomla组件教程(十九) - 创建管理员界面 删除记录删除记录在model中实现功能model中获取返回的IDS,并调用mdoel删除记录,以下是代码清单: /*** Method to delete record(s)** @access
public* @return
True on success*/function delete(){$cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );$row =& $this-&getTable();foreach($cids as $cid) {if (!$row-&delete( $cid )) {$this-&setError( $row-&getErrorMsg() );}}}JRequest::getVar()返回cid数据, 然后调用$row-&delete()删除每一行. 在controller中处理设置删除任务处理,与save是相似的。/*** remove record(s)* @return void*/function remove(){$model = $this-&getModel('hello');if(!$model-&delete()) {$msg = JText::_( 'Error: One or More Greetings Could not be Deleted' );
} else {$msg = JText::_( 'Greeting(s) Deleted' );}$this-&setRedirect( 'index.php?option=com_hello', $msg );}取消操作:/*** cancel editing a record* @return void*/function cancel(){$msg = JText::_( 'Operation Cancelled' );$this-&setRedirect( 'index.php?option=com_hello', $msg ); }到现在为止,我们就全部完成了组件管理后台的开发。欢迎您转载分享:
更多精彩:

我要回帖

更多关于 139my魔域辅助工具 的文章

 

随机推荐