2

我有 magento 1.7.0.2,现在我尝试向数据库添加一些数据。但我得到一个错误:

Notice: Undefined variable: this in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 10 Fatal error: Class 'Mage_Eav_Model_Entity_Setup' not found in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 3

这是 php 文件的一部分,它试图将一些数据添加到数据库中:

<?php
$installer = $this;
$setup = new Mage_Eav_Model_Entity_Setup('core_setup');
$installer->startSetup();

/**
 * Adding Different Attributes
 */

// adding attribute group
$setup->addAttributeGroup('catalog_product', 'Default', 'Video', 1000);

$setup->addAttribute('catalog_product', 'videobox', array(
    'group'         => 'Video',
    'input'         => 'textarea',
    'type'          => 'text',
    'label'         => 'Youtube video url',
    'backend'       => '',
    'visible'       => 1,
    'required'      => 0,
    'user_defined' => 1,
    'searchable' => 0,
    'filterable' => 0,
    'comparable'    => 0,
    'visible_on_front' => 1,
    'visible_in_advanced_search'  => 0,
    'is_html_allowed_on_front' => 0,
    'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

如何解决这个问题?提前致谢!

更新:文件有效。我添加了一段额外的代码来查看它是否有效:

<?php

require_once('app/Mage.php'); //Path to Magento
umask(0);
Mage::app(); // Change default to whatever store you want to run

echo "it's worked!";

?>

错误现在已经向下移动了一行。

Fatal error: Call to a member function startSetup() on a non-object in /var/www/vhosts/xxx/mysql4-install-0.1.0.php on line 4
4

2 回答 2

1

尝试使用

$setup = Mage::getModel("eav/entity_setup", "core_setup");

而不是直接调用。那应该行得通。

于 2014-03-15T15:57:13.913 回答
0

A problem might be class is not found in mage directory just carefully include mage.php will sure solve your issue.

$mageFilename = $_SERVER['DOCUMENT_ROOT'] . '/magento/app/Mage.php';

Use this. It worked for me.

DOCUMENT_ROOT is a server variable that represents the base directory that your code is located within.

于 2013-08-29T12:07:49.763 回答