【发布时间】:2012-01-05 20:50:16
【问题描述】:
我正在尝试使用我正在处理的管理模块在数据库中创建一个新表。我设置了什么
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
<?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 来创建表。那是对的吗?还有什么我应该做的吗?
非常感谢您对此提供的任何帮助。
【问题讨论】:
-
触发任何页面都应该安装你的模块,因为 Magento 在任何路由发生之前触发模块安装/升级过程。如果没有表出现,首先要检查的是您的模块安装脚本是否已运行,然后您可以通过检查数据库中的 core_resources 表来检查代码值为 BAR_setup 的行。
-
谢谢卡格斯。我检查了 core_resources 表,它没有显示在那里。
-
您是否在 app/etc/modules/ 中创建了一个文件来启用您的模块?
-
是的,模块正在工作,我还有其他页面正在加载。这是我正在构建的东西。
标签: php mysql database magento