如何创建一个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>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數據庫創建表,可以忽略這個屬性。driver屬性目前只能是mysql,將來Joomla可能支持更多數據庫。
轉載于:https://www.cnblogs.com/vicenteforever/articles/1633009.html
總結
以上是生活随笔為你收集整理的如何创建一个MVC模式的Joomla组件教程(九) 使用数据库下的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 也谈贝叶斯分类(C#)版本
- 下一篇: Linq to SQL 下篇