从magento模块创建一个新表 [英] Create a new table from magento module

查看:37
本文介绍了从magento模块创建一个新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用一个管理模块,正在数据库中创建一个新表.我在其中设置的内容

I am trying to have an admin module I am working on create a new table in the database. What I have setup in

app/code/local/Foo/BAR/sql/mysql4-install-0.1.0.php

app/code/local/Foo/BAR/sql/mysql4-install-0.1.0.php

<?php
  $installer = $this;
  $installer->startSetup();

  $installer->run("
    DROP TABLE IF EXISTS {$this->getTable('notes')};

    CREATE TABLE {$this->getTable('notes')} (
      `ppr_id` int(11) NOT NULL AUTO_INCREMENT,
      `notesku` bigint(20) NOT NULL,
      `notestatus`  smallint(16),
      PRIMARY KEY (`notes`)
    ) ENGINE=MyISAM  DEFAULT CHARSET=utf8
  ");

  $installer->endSetup();

,并且在app/code/local/Foo/BAR/etc/config.xml中

and this in app/code/local/Foo/BAR/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Foo_BAR>
            <version>0.1.0</version>
        </Foo_BAR>
    </modules>    

    <global>
            <models>
                <BAR>
                    <class>Foo_BAR_Model</class>
                    <resourceModel>BAR_mysql4</resourceModel>
                </BAR>

                <BAR_myslq4>
                    <class>Foo_BAR_Model_Mysql4</class>
                    <entities>
                        <BAR>
                            <table>notes</table>
                        </BAR>
                    </entities>
                </BAR_myslq4>           
            </models>

            <resources>
                <BAR_setup>
                    <setup>
                        <module>Foo_BAR</module>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </BAR_setup>
                <BAR_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </BAR_write>
                <BAR_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </BAR_read>
            </resources>
    </global>    

    <admin>
        <routers>
            <BAR>
                <use>admin</use>
                <args>
                    <module>Foo_BAR</module>
                    <frontName>bar</frontName>
                </args>
            </BAR>      
        </routers>
    </admin>



      <adminhtml>
        <menu>
            <catalog>
                <children>
                     <BAR_menu translate="title" module="BAR">
                        <title>BAR</title>
                        <children>
                            <list translate="title" module="BAR">
                                <title>Bar</title>
                                <action>bar/index/index</action>
                            </list>                       
                        </children>
                    </BAR_menu>
                </children>
            </catalog>
        </menu>
    </adminhtml>       
</config>

我使用的大小写与此示例匹配,其中我的公司为大写且模块名称全部为大写.我在想,也许是让我绊倒了吗?我的理解是,一旦我运行了访问该模块的页面,它将触发该mysql创建表.那是对的吗?我还应该做些其他事情吗?

The case I am using matches this example where my company is capitalized and the module name is all uppercase. I am thinking maybe that is tripping me up? My understanding is that once I run the page that hits that module it will trigger that mysql to create the table. Is that correct? Is there something else I should be doing?

非常感谢您对此提供的任何帮助.

I greatly appreciate any help with this.

推荐答案

如果安装/升级脚本未运行,请检查以下事项:

If a setup/upgrade script isn't running, here are some things to check:

  1. Magento是否正在加载模块?转到系统>配置>高级>高级,然后查看您的模块是否出现在禁用模块输出"列表中.如果没有,Magento根本不会加载您的模块,因此将不会运行任何安装脚本.正如Cags在他的评论中指出的那样,如果您尚未创建模块,则需要在app/etc/modules中有一个xml文件来告诉Magento加载模块.

  1. Is Magento loading your module? Go to System > Configuration > Advanced > Advanced and see if your module appears in the "Disable Module Output" list. If it doesn't, Magento isn't loading your module at all, and therefore won't run any setup scripts. As Cags noted in his comment, you'll need an xml file in app/etc/modules to tell Magento to load your module if you haven't already created one.

确保在config.xml文件的正确位置声明了您的资源.它们应位于<global>标记内(对于您而言,这似乎是正确的).

Make sure your resources are declared in the correct place in the config.xml file. They should be inside the <global> tag (this appears to be correct in your case).

确保安装文件位于正确的位置.它们应位于模块内部的sql/文件夹中.我认为这是您的问题,此示例中的安装文件应为app/code/local/Foo/BAR/sql/BAR_setup/mysql4-install-0.1.0.php

Make sure your setup files are in the correct location. They should be in a sql/ folder inside your module. I think this is your problem, the setup file in this example should be app/code/local/Foo/BAR/sql/BAR_setup/mysql4-install-0.1.0.php

已经检查了以上所有内容,如果您设置了IDE进行调试(并且如果您正在做任何认真的Magento工作,请帮个忙,并准备一个),请在设置中设置一个断点文件,并确保它被击中.

Having checked all of the above, if you have an IDE set up for debugging (and if you're doing any serious Magento work, do yourself a favor and get one up), set a breakpoint in the setup file and make sure it's being hit.

检查数据库中的core_resource表中是否有BAR_setup条目.如果存在,Magento将运行安装脚本一次,并且不会再次运行它.如果需要再次运行安装脚本,请删除该记录.同样,如果您需要重新运行升级脚本,则可以更改版本号(但请确保您再次了解运行安装/升级脚本的后果).

Check the core_resource table in the database for a BAR_setup entry. If it's there, Magento has run the setup script once and won't run it again. If you need to run your setup script again, delete this record. Likewise you can change the version numbers if you ever need to re-run upgrade scripts (but make sure you understand the consequences of running setup/upgrade scripts a second time if you do).

如果其他所有方法都失败,请查看 Alan Storm调试Magento设置脚本的指南.

If all else fails check out Alan Storm's guide to debugging Magento setup scripts.

这篇关于从magento模块创建一个新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆