【问题标题】:Error : "Call to undefined method Varien_Autoload::startSetup() "错误:“调用未定义的方法 Varien_Autoload::startSetup()”
【发布时间】: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 {
  }

【问题讨论】:

    标签: php magento


    【解决方案1】:

    下面的设置代码转到文件 app/code/local/Magentotutorial/Weblog/sql/weblog_setup/mysql4-install-0.1.0.php 而不是 setup.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();  
    

    文件:app/code/local/Magentotutorial/Weblog/Model/Resource/Setup.php 仅包含:

    class Magentotutorial_Weblog_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
    }
    

    【讨论】:

    • 我做了你所做的,但错误。但是当我复制您的代码并重新加载页面时,没有错误。无论如何感谢您的帮助。 :) 。那么为什么需要 setup.php 文件
    • 看看 setup.php 文件继承了一个核心类 Mage_Core_Model_Resource_Setup 。这里用于在 sql 文件夹中安装脚本。
    猜你喜欢
    • 2011-03-15
    • 2012-10-29
    • 2012-04-02
    • 1970-01-01
    • 2017-08-03
    • 2020-09-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    相关资源
    最近更新 更多