无法检索实体配置Magento

时间:2016-03-10 10:24:52

标签: php xml magento config

我一直在跟踪唯一的错误,因为它向我展示了多长时间。

以下是我的config.xml文件

<?xml version="1.0"?>

<config>
    <modules>
        <Maven_Questionanswer>
            <version>1.0.1</version>
        </Maven_Questionanswer>
    </modules>        
<global>
    <models>
                <questionanswer>
                    <class>Maven_Questionanswer_Model</class>
                    <resourceModel>questionanswer_resource</resourceModel>
                </questionanswer>
                <questionanswer_resource>
                    <class>Maven_Questionanswer_Model_Resource</class>
                    <entities>
                        <questionanswer>
                            <table>question</table>
                        </questionanswer>
                    </entities>
                </questionanswer_resource>
            </models>
            <resources>
                <questionanswer_setup>
                    <setup>
                        <module>Maven_Questionanswer</module>
                    </setup>
                    <connection>
                        <use>core_setup</use>
                    </connection>
                </questionanswer_setup>
                <questionanswer_write>
                    <connection>
                        <use>core_write</use>
                    </connection>
                </questionanswer_write>
                <questionanswer_read>
                    <connection>
                        <use>core_read</use>
                    </connection>
                </questionanswer_read>
            </resources>
    </global>
</config>

/app/code/local/Maven/Questionanswer/Model/Question.php

 <?php
    /**
    * 
    */

    class Maven_Questionanswer_Model_Question extends Mage_Core_Model_Abstract
    {
         public function _construct()
         {
             parent::_construct();
             $this->_init('questionanswer/question');
         }
    }

    ?>

/app/code/local/Maven/Questionanswer/Model/Resource/Question.php

<?php
class Maven_Questionanswer_Model_Resource_Question extends Mage_Core_Model_Resource_Db_Abstract
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    public function _construct()
    {
        $this->_init('questionanswer/question', 'question_id');
    }
}
?>

/magento1.9.2/app/code/local/Maven/Questionanswer/Model/Resource/Question/Collection.php

<?php
/**
* 
*/
class Maven_Questionanswer_Model_Resource_Question_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract 
{

    protected function _construct()
    {
            $this->_init('questionanswer/question');
    }
}
?>

/app/code/local/Maven/Questionanswer/sql/questionanswer_setup/install-1.0.1.php



<?php

$installer = $this;
 $installer->startSetup();
 $table = $installer->getConnection()->newTable($installer->getTable('questionanswer/question'))
    ->addColumn('question_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'unsigned' => true,
        'nullable' => false,
        'AUTO_INCREMENT'=>true,
        'primary' => true,
        'identity' => true,
        ), 'Question ID')
    ->addColumn('username', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
        ), 'Username')
    ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
        ), 'Email username')
    ->addColumn('question', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        ), 'Question')
    ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Product ID')
    ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Store ID')
    ->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Status')
    ->setComment('questionanswer questionanswer/question entity table');
    $installer->getConnection()->createTable($table);

$installer->endSetup();
?>

我在哪里弄错了?我能理解。

2 个答案:

答案 0 :(得分:3)

您缺少资源设置文件。 这些行:

<resources>
    <questionanswer_setup>
        <setup>
            <module>Maven_Questionanswer</module>
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </questionanswer_setup>
        <questionanswer_write>
            <connection>
                <use>core_write</use>
            </connection>
        </questionanswer_write>
        <questionanswer_read>
            <connection>
                <use>core_read</use>
            </connection>
        </questionanswer_read>
 </resources>

应该是:

<resources>
    <questionanswer_setup>
        <setup>
            <module>Maven_Questionanswer</module>
            <class>Maven_Questionanswer_Model_Resource_Setup</class>
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </questionanswer_setup>
        <questionanswer_write>
            <connection>
                <use>core_write</use>
            </connection>
        </questionanswer_write>
        <questionanswer_read>
            <connection>
                <use>core_read</use>
            </connection>
        </questionanswer_read>
 </resources>

新行:

<class>Maven_Questionanswer_Model_Resource_Setup</class>

资源设置文件应该是:

<?php

class Maven_Questionanswer_Model_Resource_Setup extends Mage_Core_Model_Resource_Setup {
}

希望有所帮助

答案 1 :(得分:2)

请尝试以下代码,

&#13;
&#13;
<?php

$installer = $this;
 $installer->startSetup();
 $table = $installer->getConnection()->newTable($installer->getTable('question'))
    ->addColumn('question_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        'unsigned' => true,
        'nullable' => false,
        'AUTO_INCREMENT'=>true,
        'primary' => true,
        'identity' => true,
        ), 'Question ID')
    ->addColumn('username', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
        ), 'Username')
    ->addColumn('email', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        'nullable' => false,
        ), 'Email username')
    ->addColumn('question', Varien_Db_Ddl_Table::TYPE_TEXT, null, array(
        ), 'Question')
    ->addColumn('product_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Product ID')
    ->addColumn('store_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Store ID')
    ->addColumn('status', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
        ), 'Status')
    ->setComment('questionanswer questionanswer/question entity table');
    $installer->getConnection()->createTable($table);

$installer->endSetup();
?>
&#13;
&#13;
&#13;