所有路径都是从根目录开始的:

1.建立模块的配置文件:

路径:app/etc/models/下建一个文件(模块名称是Orderlottery)为Bf170_Orderlottery.xml,内容如下:

<?xml version="1.0"?>
  <!--
  /*
   * NOTICE OF LICENSE
   */
  -->
  <config>
       <modules>
          <Bf170_Orderlottery>
              <active>true</active>
              <codePool>local</codePool>
          </Bf170_Orderlottery>
      </modules>
  </config>

2.开始建立模块,建立模块需要建立几个文件夹:

路径:app/code/local/Bf170/Orderlottery/下建立模块需要的文件夹:

1>Block

2>controllers

3>etc

4>Helper

5>Model

6>sql

文件夹建立好之后开始对模块orderlottery建配置文件adminhtml.xml和config.xml:

首先对config.xml文件来配置如下:

<?xml version="1.0" encoding="UTF-8"?>
 <!--
 * NOTICE OF LICENSE
 *
 -->
 <config>
     <modules>.................................................................................................模块
         <Bf170_Orderlottery>.............................................................................模块版本
             <version>1.0.0</version>
         </Bf170_Orderlottery>
     </modules>
     <global>....................................................................................................全局
         <helpers>..............................................................................................辅助功能
             <orderlottery>
                 <class>Bf170_Orderlottery_Helper</class>
             </orderlottery>
         </helpers>
         <blocks>..............................................................................................页面block
             <orderlottery>
                 <class>Bf170_Orderlottery_Block</class>
             </orderlottery>
         </blocks>
         <models>.............................................................................................表对象
             <orderlottery>
                 <class>Bf170_Orderlottery_Model</class>......................................表对象类
                 <resourceModel>orderlottery_mysql4</resourceModel>....................表对象资源
             </orderlottery>
             <orderlottery_mysql4>
                 <class>Bf170_Orderlottery_Model_Mysql4</class>
                 <entities>
                     <item>
                         <table>orderlottery_item</table>
                     </item>
                 </entities>
             </orderlottery_mysql4>
         </models>
         <resources>.......................................................................................资源
             <orderlottery_setup>
                 <setup>
                     <module>Bf170_Orderlottery</module>
                 </setup>
                 <connection>
                     <use>core_setup</use>
                 </connection>
             </orderlottery_setup>
             <orderlottery_write>.......................................................................可写
                 <connection>
                     <use>core_write</use>
                 </connection>
             </orderlottery_write>
             <orderlottery_read>.......................................................................可读
                 <connection>
                     <use>core_read</use>
                 </connection>
             </orderlottery_read>
         </resources>

<events>.........................................................................................加载的事件(事件放在不同位置,使用的地方也不一样,可放admin,global,frontend)

<events/>
     </global>

<frontend>..........................................................................................前台
         <routers>
             <orderlottery>
                 <use>standard</use>
                 <args>
                     <module>Bf170_Orderlottery</module>
                     <frontName>orderlottery</frontName>
                 </args>
             </orderlottery>
         </routers>
         <layout>.........................................................................................这个模块所加载的模板
             <updates>
                 <orderlottery module="Bf170_Orderlottery">
                     <file>orderlottery.xml</file>
                 </orderlottery>
             </updates>
         </layout>
     </frontend>
     <adminhtml>.........................................................................................后台
         <!-- 相应的adminhtml定义挪到了adminhtml.xml -->
     </adminhtml>
     <admin>
         <routers>
             <orderlottery_adminhtml>
                 <use>admin</use>
                 <args>
                     <module>Bf170_Orderlottery_Adminhtml</module>
                     <frontName>orderlottery_adminhtml</frontName>
                 </args>
             </orderlottery_adminhtml>
         </routers>
     </admin>
 </config>

现在对adminhtml.xml文件来配置如下:

<?xml version="1.0" encoding="UTF-8"?>
  <!--
   * NOTICE OF LICENSE
   *
   -->
  <config>
      <menu>...........................................................................................................后台菜单
          <orderlottery translate="title" module="orderlottery">......................................这里名称自定义
              <title>后台插件练习</title>..........................................................................菜单名称
              <sort_order>9999</sort_order>...............................................................位置
              <children>
                  <item_index translate="title" module="orderlottery">...............................主菜单的子菜单
                      <title>信息查询</title>
                      <sort_order>100</sort_order>
                      <action>orderlottery_adminhtml/item/index</action>..........................点击所访问的路径
                  </item_index>
              </children>
          </orderlottery>
      </menu>
      <acl>..............................................................................................................权限
          <resources>
              <admin>
                  <children>
                      <orderlottery translate="title" module="orderlottery">
                          <title>后台插件练习</title>
                          <sort_order>120</sort_order>
                          <children>
                              <manage translate="title">
                                  <title>管理</title>
                                  <sort_order>0</sort_order>
                              </manage>
                          </children>
                      </orderlottery>
                  </children>
              </admin>
          </resources>
      </acl>
  </config>

把以上两个文件配置完成之后你就可以到后台看到这个模块就已经启动了,菜单也会加载出来.

3.现在接下来就是对这个模块的"表"对象进行建立了.

在建立表之前先需要建几个文件(就是这张表对象,這张表名是orderlottery_item)

1> 需要在Model這个文件夹里建文件夹  Mysql4和文件Item.php(Item.php的内容如下)

<?php
       /*
   * NOTICE OF LICENSE
   */
  class Bf170_Orderlottery_Model_Item extends Mage_Core_Model_Abstract {
   
      // 如果需要相应的事件相应逻辑
      protected $_eventPrefix = 'orderlottery_item';

      //=============== Internal Processing (automatic) ============= //
      protected function _construct() {
          // 指向相应的 Resource (Model)
          $this->_init('orderlottery/item');
      }
    
      // 一般在保存前,赋予更新时间(初次保存,赋予创建时间)
      protected function _beforeSave() {
          parent::_beforeSave();
          //For new object which does not specify 'created_at'
          if(!$this->getId() && !$this->getData('created_at')){
              $this->setData('created_at', now());
          }
          //Always specify 'updated_at'
          $this->setData('updated_at', now());
          return $this;
      }
 2> 在Mysql4文件里建好Item文件夹和文件Item.php,内容如下:

  <?php
    /*
     * NOTICE OF LICENSE
     */
    class Bf170_Orderlottery_Model_Mysql4_Item extends Mage_Core_Model_Mysql4_Abstract {
    
        // 指向相应的 Table以及Primary ID
        protected function _construct() {
            $this->_init('orderlotteryt/item', 'entity_id');
        }
    }

3> 在Item文件夹里建好Collection.php,内容如下:

    <?php
    /*
     * NOTICE OF LICENSE
     */
    class Bf170_Orderlottery_Model_Mysql4_Item_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
    
        public function _construct() {
            $this->_init('orderlottery/item');
        }
    }

4> 在sql文件夹里建立文件夹orderlottery_setup,再在orderlottery_setup这个文件夹里建一个文件mysql4-install-1.0.0.php,这个文件内容如下:

      <?php
    /*
     * NOTICE OF LICENSE
     */
    $installer = $this;
    $installer->startSetup();
    $installer->run("
    -- DROP TABLE IF EXISTS {$this->getTable('orderlottery_item')};
    CREATE TABLE {$this->getTable('orderlottery_item')} (
      `entity_id` int(10) unsigned NOT NULL auto_increment COMMENT 'Entity ID',
      `product_id` int(10) unsigned COMMENT 'Product ID',
      `price` decimal(12, 4) COMMENT 'Price',
      `name` varchar(255) COMMENT 'Name',
      `status` smallint(5) unsigned COMMENT 'Status',
      `created_at` timestamp NULL COMMENT 'Created At',
      `updated_at` timestamp NULL COMMENT 'Updated At',
      PRIMARY KEY  (`entity_id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='这张表的注释';
     ");
  $installer->endSetup();

未完待续。。。。。

magento模块的建立的更多相关文章

  1. Magento模块升级修改数据库表结构

    Magento支持在模块中创建.删除.更新数据库表及字段.通过该方式,在插件开发的过程中,添加和修改字段变成了一件非常轻松的事情.只需要修改模块的版本号,同时在文件中添加一个符合命名规则的脚本就可以了 ...

  2. Drupal 7 模块开发 建立模块帮助信息(hook_help)

    建立模块请參考 <Drupal 7 模块开发 建立> 假设你要支持中文,文件格式必须保存为 UTF-8.NO BOM ------------------------------ hook ...

  3. Magento 模块开发之DispatchEvent

    在这一章节中.我们来了解 Magento 中的事件分发机制 Mage::dispatchEvent() 在创建自己的模块时, Event 事件的分发将会变成十分实用且有效 以个人的经验. 事件的分发使 ...

  4. 如何创建magento模块z之Hello World例子(转)

    步骤:1.创建一个Hello World模块2.为这个模块配置路由3.为这个模块创建执行控制器 创建Hello World模块 创建模块的结构目录:app/core/local/Sjolzy/Hell ...

  5. Magento开发文档(一):Magento入门

    开始之前,首先声明下,Magento开发者手册由Alan Storm发表在Magento官方网站上.总共分八个部分,由浅入深的介绍了Magento的MVC架构及Magento中使用的比较特殊的EAV模 ...

  6. Magento 使用心得

    Modules->模块 Controller->控制器 Model->模型 Magento是这个星球上最强大的购物车网店平台.当然,你应该已经对此毫无疑问了.不过,你可能还不知道,M ...

  7. Magento入门开发教程

    Modules->模块 Controller->控制器 Model->模型 Magento是这个星球上最强大的购物车网店平台.当然,你应该已经对此毫无疑问了.不过,你可能还不知道,M ...

  8. Magento强大的配置系统

    Magento的配置系统就像是Magento的心脏,支撑着Magento的运行.这套配置系统掌管着几乎所有"module/model/class/template/etc".它把整 ...

  9. Magento WebServices SOAP API 创建和使用

    首先 SOAP 简介: http://baike.baidu.com/view/1695890.htm?fromtitle=SOAP 然后简单介绍下Magento API.Magento API干啥用 ...

随机推荐

  1. JSON.stringify 方法

    浅谈 JSON.stringify 方法   用过 json 的应该都知道,把一个对象通过 stringify 之后提交给后台或者存储在 Storage 里是很常用的手段.但是 IE6-8 下没有 J ...

  2. .NET MVC4 实训记录之五(访问自定义资源文件)

    .Net平台下工作好几年了,资源文件么,大多数使用的是.resx文件.它是个好东西,很容易上手,工作效率高,性能稳定.使用.resx文件,会在编译期动态生成已文件名命名的静态类,因此它的访问速度当然是 ...

  3. every、some、filter、map、forEach 方法的区别总结

    API功能描述: [every]:Boolean 遍历数组并执行回调,如果每个数组元素都能通过回调函数的测试则返回true,否则返回false.一旦返回false,将立即终止循环. [some]:Bo ...

  4. cvs vss svn和git比较

    cvs vss svn和git比较 特征 CVS Git Mercurial Subversion 是否原子提交 CVS: 没有. CVS提交不是原子的 Git: 是的. 提交都是原子的 Mercur ...

  5. nhibernate+autofac+mvc的demo

    想自己做一个小的demo.目的是能够提供一个系统架构,在这个基础上,可以快速开发一些小型的系统.

  6. Paint与Canvas的简单用法

    参考:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=278237 自定义View 重写onDraw方法 package com. ...

  7. 企业架构研究总结(33)——TOGAF架构内容框架之架构制品(上)

    4. 架构制品(Architectural Artifacts) 架构制品是针对某个系统或解决方案的模型描述,与架构交付物和构建块相比,架构制品既不是架构开发方法过程各阶段的合约性产物,亦不是企业中客 ...

  8. WCF/WPF公司内部订餐程序开发

    WCF/WPF公司内部订餐程序开发 (服务端篇) 上班的第一天,群里讨论关于订餐的问题,所以想到了要不要自己开发一个公司内部的订餐系统呢?方便公司内部员工的订餐,有了想法就简单的实践了下 . 实现还是 ...

  9. Git - error: RPC failed; result=22, HTTP code = 401 fatal: The remote end hung up unexpectedly

    在用Git管理代码版本时,用git push命令提交代码,提示: 有以下几个可能性: Git 版本过低.GitCafe 推荐使用的 Git 版本是 >= 1.7. $ git --version ...

  10. 【Yom框架】漫谈个人框架的设计之二:新的IRepository接口+搜索和排序解耦(+基于Castle实现)

    经过了上篇IRepository和IRepository<T>的讨论[文章地址为:http://www.cnblogs.com/yomho/p/3296759.html] 我选择了IRep ...