1
首先建立一个模块:
app/code/community/Terry/Zhao
下面建立
Block,controllers,Model,etc,sql,Helper文件夹
2
app/etc/modules下面
建立配置文件
Terry_zhao.xml
内容:
<?xml version="1.0" ?>
<config>
<modules>
<Terry_Zhao>
<active>true</active>
<codePool>community</codePool>
</Terry_Zhao>
</modules>
</config>
3
app/code/community/Terry/Zhao/etc
建立配置文件config.xml
<?xml version="1.0" ?>
<config>
<modules>
<Terry_Zhao>
<version>1.10</version>
</Terry_Zhao>
</modules>
<frontend>
<routers>
<zhao>
<use>standard</use>
<args>
<module>Terry_Zhao</module>
<frontName>zhao</frontName>
</args>
</zhao>
</routers>
</frontend>
<global>
<models>
<zhao>
<class>Terry_Zhao_Model</class>
<resourceModel>zhao_mysql4</resourceModel>
</zhao>
<zhao_mysql4>
<class>Terry_Zhao_Model_Mysql4</class>
<entities>
<zhao>
<table>zhao</table>
</zhao>
<zhao_store>
<table>zhao_store</table>
</zhao_store>
</entities>
</zhao_mysql4>
</models>
<resources>
<zhao_setup>
<setup>
<module>Terry_Zhao</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</zhao_setup>
<zhao_write>
<connection>
<use>core_write</use>
</connection>
</zhao_write>
<zhao_read>
<connection>
<use>core_read</use>
</connection>
</zhao_read>
</resources>
<blocks>
<profile>
<class>Terry_Zhao_Block</class>
</profile>
</blocks>
<helpers>
<profile>
<class>Terry_Zhao_Helper</class>
</profile>
</helpers>
</global>
</config>
4 在目录 app/code/community/Terry/Zhao/sql/zhao_setup 下面建立文件mysql4-install-0.1.0.php
内容:
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
DROP TABLE IF EXISTS `{$this->getTable('zhao/zhao')}`;
CREATE TABLE {$this->getTable('zhao/zhao')} (
`profile_id` smallint(6) NOT NULL AUTO_INCREMENT,
`category_id` int(11) NOT NULL,
`thumbnail` varchar(255) NOT NULL,
`thumbnail_position` int(11) NOT NULL,
`picture` varchar(255) NOT NULL,
`file` varchar(255) NOT NULL,
`content_heading` varchar(255) NOT NULL DEFAULT '',
`content` mediumtext,
`meta_keywords` text NOT NULL,
`meta_description` text NOT NULL,
`creation_time` datetime DEFAULT NULL,
`update_time` datetime DEFAULT NULL,
`is_active` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`profile_id`),
KEY `identifier` (`content_heading`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `{$this->getTable('zhao/zhao_store')}`;
CREATE TABLE {$this->getTable('zhao/zhao_store')} (
`profile_id` smallint(6) NOT NULL,
`store_id` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`profile_id`,`store_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='CMS Profiles to Stores';
");
$installer->endSetup();
OK。只要刷新下缓存,或者访问这个模块后,查看数据库,就会发现建立了2个数据表
zhao
和
zhap_store
两个数据库表。
so easy!!!