博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
magento ----使用magento内部机制建立数据库表
阅读量:4199 次
发布时间:2019-05-26

本文共 2587 字,大约阅读时间需要 8 分钟。

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!!!

 

 

 

 

 

 

 

 

 

 

 

转载地址:http://cwcli.baihongyu.com/

你可能感兴趣的文章
测试设计与测试项目实战训练
查看>>
HP Sprinter:敏捷加速器
查看>>
单元测试培训PPT
查看>>
adb常用命令
查看>>
通过LR监控Linux服务器性能
查看>>
通过FTP服务的winsockes录制脚本
查看>>
LRwinsocket协议测试AAA服务器
查看>>
Net远程管理实验
查看>>
反病毒专家谈虚拟机技术 面临两大技术难题
查看>>
几种典型的反病毒技术:特征码技术、覆盖法技术等
查看>>
性能测试一般过程与LR性能测试过程
查看>>
Software Security Testing软件安全测试
查看>>
SQL注入漏洞全接触--进阶篇
查看>>
SQL注入漏洞全接触--高级篇
查看>>
SQL注入法攻击一日通
查看>>
菜鸟入门级:SQL注入攻击
查看>>
用vbs来写sql注入等80端口的攻击脚本
查看>>
C# 检查字符串,防SQL注入攻击
查看>>
关于对SQL注入80004005 及其它错误消息分析
查看>>
即时通软件性能测试(与宴宾的对话)
查看>>