【问题标题】:Magento Fatal error: Call to a member function getAttribute() on a non-object in Js.php on line 149Magento 致命错误:在第 149 行的 Js.php 中的非对象上调用成员函数 getAttribute()
【发布时间】:2012-05-11 19:04:10
【问题描述】:

我一生都在为真正进入我域上的 Magento 后端而奋斗。我已经重新安装了几次,但我无法在没有弹出一些错误的情况下进入。这是最新的:

致命错误:在第 149 行的 /app/code/core/Mage/Core/Helper/Js.php 中的非对象上调用成员函数 getAttribute()

当我登录管理区域时弹出上述错误,这是我看到的唯一内容。我刷新、清除缓存、使用不同的浏览器(我尝试过最新版本的 Firefox 和 Chrome)和同样的错误。

有人能帮帮我吗?我已经做了几天了,试图自己解决这个问题。但我完全没有想法。谢谢!

Js.php 文件在下面

<?php

类 Mage_Core_Helper_Js 扩展了 Mage_Core_Helper_Abstract { /** * 缓存键 */ const JAVASCRIPT_TRANSLATE_CONFIG_KEY = 'javascript_translate_config';

/**
 * Translate file name
 */
const JAVASCRIPT_TRANSLATE_CONFIG_FILENAME = 'jstranslator.xml';

/**
 * Array of senteces of JS translations
 *
 * @var array
 */
protected $_translateData = null;

/**
 * Translate config
 *
 * @var Varien_Simplexml_Config
 */
protected $_config = null;

/**
 * Retrieve JSON of JS sentences translation
 *
 * @return string
 */
public function getTranslateJson()
{
    return Mage::helper('core')->jsonEncode($this->_getTranslateData());
}

/**
 * Retrieve JS translator initialization javascript
 *
 * @return string
 */
public function getTranslatorScript()
{
    $script = 'var Translator = new Translate('.$this->getTranslateJson().');';
    return $this->getScript($script);
}

/**
 * Retrieve framed javascript
 *
 * @param   string $script
 * @return  script
 */
public function getScript($script)
{
    return '<script type="text/javascript">//<![CDATA[
    '.$script.'
    //]]></script>';
}

/**
 * Retrieve javascript include code
 *
 * @param   string $file
 * @return  string
 */
public function includeScript($file)
{
    return '<script type="text/javascript" src="'.$this->getJsUrl($file).'"></script>'."\n";
}

/**
 * Retrieve
 *
 * @param   string $file
 * @return  string
 */
public function includeSkinScript($file)
{
    return '<script type="text/javascript" src="'.$this->getJsSkinUrl($file).'"></script>';
}

/**
 * Retrieve JS file url
 *
 * @param   string $file
 * @return  string
 */
public function getJsUrl($file)
{
    return Mage::getBaseUrl('js').$file;
}

/**
 * Retrieve skin JS file url
 *
 * @param   string $file
 * @return  string
 */
public function getJsSkinUrl($file)
{
    return Mage::getDesign()->getSkinUrl($file, array());
}

/**
 * Retrieve JS translation array
 *
 * @return array
 */
protected function _getTranslateData()
{
    if ($this->_translateData === null) {
        $this->_translateData = array();
        $messages = $this->_getXmlConfig()->getXpath('*/message');
        if (!empty($messages)) {
            foreach ($messages as $message) {
                $messageText = (string)$message;
                $module = $message->getParent()->getAttribute("module");
                $this->_translateData[$messageText] = Mage::helper(empty($module) ? 'core' : $module
                )->__($messageText);
            }
        }

        foreach ($this->_translateData as $key => $value) {
            if ($key == $value) {
                unset($this->_translateData[$key]);
            }
        }
    }
    return $this->_translateData;
}

/**
 * Load config from files and try to cache it
 *
 * @return Varien_Simplexml_Config
 */
protected function _getXmlConfig()
{
    if (is_null($this->_config)) {
        $canUsaCache = Mage::app()->useCache('config');
        $cachedXml = Mage::app()->loadCache(self::JAVASCRIPT_TRANSLATE_CONFIG_KEY);
        if ($canUsaCache && $cachedXml) {
            $xmlConfig = new Varien_Simplexml_Config($cachedXml);
        } else {
            $xmlConfig = new Varien_Simplexml_Config();
            $xmlConfig->loadString('<?xml version="1.0"?><jstranslator></jstranslator>');
            Mage::getConfig()->loadModulesConfiguration(self::JAVASCRIPT_TRANSLATE_CONFIG_FILENAME, $xmlConfig);

            if ($canUsaCache) {
                Mage::app()->saveCache($xmlConfig->getXmlString(), self::JAVASCRIPT_TRANSLATE_CONFIG_KEY,
                    array(Mage_Core_Model_Config::CACHE_TAG));
            }
        }
        $this->_config = $xmlConfig;
    }
    return $this->_config;
}

}

【问题讨论】:

    标签: magento


    【解决方案1】:

    你清除了缓存?如何?你也清除会话吗?我们现在有一个功能,这意味着我们必须不时手动清除这些,然后才能自己进入管理。这是 SSH shell 的输出...

    var# ls
    ./  ../  cache/  export/  locks/  log/  package/  pear/  report/  session/
    var# rm -rf cache/*
    var# rm -rf session/*
    

    所以我写了一个网页/php-script 来做这件事,这样我们的员工就可以在没有 SSH 的情况下做到这一点:

    <pre><?php
    $output;
    $retval;
    $errors="";
    $command="pwd";
    exec ( $command ,  &$output, &$retval  );
    $path=$output[0];
    unset($output);
    echo "rm -rf $path/var/cache/*\n";
    if( 0 ) {   // change to 1 after seeing the above looks ok!
        $command="rm -rf $path/var/cache/*";
        exec ( $command ,  &$output, &$retval  );
        echo "<b>$command</b> returned $retval\n";
        if($retval > 0)
            $errors .= "There was a problem deleting cache files.\n";
        // ------------------------------------------------
        $command="ls -alh $path/var/cache";
        exec ( $command ,  &$output, &$retval  );
        echo "<b>$command</b> returned $retval; the directory listing should only have . and ..\n\$output:";
        print_r($output);
        unset($output);
        // ------------------------------------------------
        $command="rm -rf $path/var/session/*";
        exec ( $command ,  &$output, &$retval  );
        echo "<b>$command</b> returned $retval\n";
        if($retval > 0)
            $errors .= "There was a problem deleting session files.\n";
        // ------------------------------------------------
        $command="ls -alh $path/var/session";
        exec ( $command ,  &$output, &$retval  );
        echo "<b>$command</b> returned $retval; the directory listing should only have . and ..\n\$output:";
        print_r($output);
        unset($output);
    }
    if( strlen($errors) == 0 )
        echo "<h2>Yaay! you can get into admin again...</h2>";
    else
        echo "<h2 style=\"color:red\">Boo! something went wrong...</h2>$errors\n";
    ?></pre>
    

    将 if(0) 更改为 1 后,如果您访问此文件(我称之为 __cache_clear.php),输出应如下所示:

    rm -rf /home/username/public_html/var/cache/*
    rm -rf /home/username/public_html/var/cache/* returned 0
    ls -alh /home/username/public_html/var/cache returned 0; the directory listing should only have . and ..
    $output:Array
    (
        [0] => total 16K
        [1] => drwxrwxrwx  2 username username 4.0K May 13 19:42 .
        [2] => drwxr-xr-x 10 username username 4.0K May 10 15:17 ..
    )
    rm -rf /home/username/public_html/var/session/* returned 0
    ls -alh /home/username/public_html/var/session returned 0; the directory listing should only have . and ..
    $output:Array
    (
        [0] => total 248K
        [1] => drwxrwxrwx  2 username username 232K May 13 19:42 .
        [2] => drwxr-xr-x 10 username username 4.0K May 10 15:17 ..
    )
    Yaay! you can get into admin again...
    

    请注意,“用户名”是您在网络托管公司分配的用户名,并且会有所不同。我使脚本动态化,一旦放置在 Magento 文件夹中,它就会正常运行。

    【讨论】:

      猜你喜欢
      • 2015-07-27
      • 1970-01-01
      • 2010-12-20
      • 2015-06-16
      • 2016-02-02
      • 2014-05-06
      • 1970-01-01
      • 2023-03-07
      • 1970-01-01
      相关资源
      最近更新 更多