Magento - Fatal error: Class name must be a valid object or a string

风格不统一 提交于 2019-12-10 13:29:23

问题


I'm having a problem with a Magento installation that I hope someone can help me with.

I suddenly started getting the following error message when I accessed the site:

Fatal error: Class name must be a valid object or a string in /app/code/core/Mage/Core/Model/Resource.php on line 215

The function that this refers to is:

/**
  * Get connection type instance
  *
  * Creates new if doesn't exist
  *
  * @param string $type
  * @return Mage_Core_Model_Resource_Type_Abstract
  */
public function getConnectionTypeInstance($type)
{
    if (!isset($this->_connectionTypes[$type])) {
        $config = Mage::getConfig()->getResourceTypeConfig($type);
        $typeClass = $config->getClassName();
        $this->_connectionTypes[$type] = new $typeClass();
    }
    return $this->_connectionTypes[$type];
}

This is line 215:

$this->_connectionTypes[$type] = new $typeClass();

I've searched for someone with a similar issue but not had any luck so i'm stuck and really need to get this resolved

Can anyone help?


回答1:


I had the same problem here. Try to add

<type>pdo_mysql</type>

in your local.xml file inside the connection node. It should be something like this:

        <default_setup>
            <connection>
                <host><![CDATA[localhost]]></host>
                <username><![CDATA[your_user]]></username>
                <password><![CDATA[your_pass]]></password>
                <dbname><![CDATA[your_db]]></dbname>
                <initStatements><![CDATA[SET NAMES utf8]]></initStatements>
                <model><![CDATA[mysql4]]></model>
                <type><![CDATA[pdo_mysql]]></type>
                <pdoType><![CDATA[]]></pdoType>
                <active>1</active>
            </connection>
        </default_setup>

And also try to check if your editor added line breaks or blank spaces when auto-formating your xml configuration file. Sometimes the value for the type node (and other nodes) are placed in the line bellow, and it breaks the parse. So, make sure that there is no space or line breaks around the values in your xml file.



来源:https://stackoverflow.com/questions/13377491/magento-fatal-error-class-name-must-be-a-valid-object-or-a-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!