【发布时间】:2015-07-27 04:24:18
【问题描述】:
我正在尝试类似教程的代码
http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-6.html
但是当我将代码创建表添加到 setup.php 文件中时出现错误。请帮助我像教程一样创建表。感谢您的帮助。
我的错误:
致命错误:在第 3 行调用 C:\xampp\htdocs\magento\app\code\local\Magentotutorial\Weblog\Model\Resource\Setup.php 中未定义的方法 Varien_Autoload::startSetup()
config.xml
<?xml version="1.0"?>
<config>
<frontend>
<routers>
<weblog>
<use>standard</use>
<args>
<module>Magentotutorial_Weblog</module>
<frontName>weblog</frontName>
</args>
</weblog>
</routers>
</frontend>
<global>
<models>
<weblog>
<class>Magentotutorial_Weblog_Model</class>
</weblog>
<weblog_resource>
<class>Magentotutorial_Weblog_Model_Resource</class>
<entities>
<blogpost>
<table>blog_posts</table>
</blogpost>
</entities>
</weblog_resource>
</models>
<resources>
<weblog_setup>
<setup>
<module>Magentotutorial_Weblog</module>
<class>Magentotutorial_Weblog_Model_Resource_Setup</class>
</setup>
</weblog_setup>
</resources>
</global>
</config>
安装程序.php
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE `{$installer->getTable('weblog/blogpost')}` (
`blogpost_id` int(11) NOT NULL auto_increment,
`title` text,
`post` text,
`date` datetime default NULL,
`timestamp` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`blogpost_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO `{$installer->getTable('weblog/blogpost')}` VALUES (1,'My New Title','This is a blog post','2009-07-01 00:00:00','2009-07-02 23:12:30');
");
$installer->endSetup();
class Magentotutorial_Weblog_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
}
【问题讨论】: