【发布时间】:2018-04-25 08:38:17
【问题描述】:
我是 Magento 的新手。我正在尝试使用安装脚本在数据库中创建一个表。该网站是托管的。我遵循了一些教程。它们看起来都一样。我遵循了每一步,但表不是创建。有人能告诉我哪里出错了吗? 这些是我遵循的步骤。 首先,我在 app/code 中创建了名为 Sitepoint 的文件夹。然后我在 Sitepont 中创建了一个 Articles 文件夹。这就是它的外观
app/code/local/Sitepoint/文章
然后我在站点点内创建了 etc 文件夹
app/code/local/Sitepoint/Articles/等
etc floder由config.xml文件组成。它包含以下代码。
<global>
<models>
<articles>
<class>Sitepoint_Articles_Model</class> <!-- Model class files -->
<resourceModel>articles_mysql4</resourceModel> <!--Resource model -->
</articles>
<articles_mysql4>
<class>Sitepoint_Articles_Model_Mysql4</class>
<entities>
<articles>
<table>articles</table> <!-- Db table name -->
</articles>
</entities>
</articles_mysql4>
</models>
<resources>
<articles_setup>
<setup>
<module>Sitepoint_Articles</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</articles_setup>
<articles_write>
<connection>
<use>core_write</use>
</connection>
</articles_write>
<articles_read>
<connection>
<use>core_read</use>
</connection>
</articles_read>
</resources>
</global>
然后我通过以下方式为sql和articles_setup创建了文件夹 app/code/local/Sitepoint/Articles/sql/articles_setup 在其中,包含 mysql4-install-0.1.0.php 文件,该文件具有以下代码。
<?php
$installer = $this;
$installer->startSetup();
$installer->run("-- DROP TABLE IF EXISTS {$this->getTable('articles')};
CREATE TABLE {$this->getTable('articles')} (
`articles_id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(255) NOT NULL default '',
`short_desc` text NOT NULL default '',
`long_desc` text NOT NULL default '',
`status` tinyint(2) NOT NULL default '0',
`created_time` datetime NULL,
`update_time` datetime NULL,
PRIMARY KEY (`articles_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
");
$installer->endSetup();
?>
我按照本教程进行操作 => https://www.sitepoint.com/magento-install-upgrade-data-scripts-explained/ 但是没有创建表格。我尝试了一些其他教程。它们都提供相同的方式。有人可以帮助我吗?
【问题讨论】:
-
你在
app/etc/modules中添加了Sitepoint_Articles.xml吗? -
我已经添加了 Sitepoint_Articles.xml,但是有一个拼写错误。我拼写的是 sitepoint 而不是 SItepoint。谢谢。它现在可以工作了
标签: magento magento-1.7 magento-1.9 magento2