日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

如何创建一个MVC模式的Joomla组件教程(九) 使用数据库下

發(fā)布時間:2025/3/20 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 如何创建一个MVC模式的Joomla组件教程(九) 使用数据库下 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

你可能看到了表的前綴非常奇怪。Joomla將替換這個前綴,用安裝時候指定的內(nèi)容。對于通常的安裝,這個表名將是jos_hello,這樣可以多個安裝使用一個數(shù)據(jù)庫,并且能夠避免表名沖突。

表中有兩個字段,一是id,是主鍵,一是greeting.

以上內(nèi)容保存在 install.utf.sql.

創(chuàng)建卸載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>2007 02 22</creationDate>
?? <author>John Doe</author>
?? <authorEmail> john.doe@example.org 為防備電子郵件地址收集器,這個 E-mail 地址被隱藏,你的瀏覽器必須支持 Javascript 才可看到這個郵件地址 </authorEmail>
?? <authorUrl>http://www.example.org</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 folder
???????? to copy FROM in the package to install therefore files copied
???????? in 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數(shù)據(jù)庫創(chuàng)建表,可以忽略這個屬性。driver屬性目前只能是mysql,將來Joomla可能支持更多數(shù)據(jù)庫。

轉(zhuǎn)載于:https://www.cnblogs.com/vicenteforever/articles/1633009.html

總結(jié)

以上是生活随笔為你收集整理的如何创建一个MVC模式的Joomla组件教程(九) 使用数据库下的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。