Magento 1.9 – Fixing ‘Call to Undefined Method Varien_Autoload::startSetup()’ Error

magento-1.9

I'm trying code like tutorial

http://devdocs.magento.com/guides/m1x/magefordev/mage-for-dev-6.html

But when i add code create table into setup.php file i have an error .Please help me create table like tutorial . Thanks for your help .

My error:

Fatal error: Call to undefined method Varien_Autoload::startSetup() in C:\xampp\htdocs\magento\app\code\local\Magentotutorial\Weblog\Model\Resource\Setup.php on line 3

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>

Setup.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 {
  }

Best Answer

Contents of your setup.php should be

 class Magentotutorial_Weblog_Model_Resource_Setup extends    Mage_Core_Model_Resource_Setup {
  }

in your mysql4-install-0.1.0.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();

Currently it looks you've combined both of them :)

Related Topic