2012-01-05 16 views
0

我已經創建了一個自定義模塊來創建自定義數據庫表。我一直在關注Alan Storm的教程http://alanstorm.com/magento_setup_resourceshttp://alanstorm.com/magento_models_orm以創建自定義數據庫表。在Magento中找不到自定義數據庫表

我的模塊條目顯示在core_resource表中,但實際沒有顯示出來。

這是我的config.xml代碼

<?xml version="1.0"?> 
<config> 
<modules> 
    <Ajzele_SimpleModel> 
     <version>0.0.1</version> 
    </Ajzele_SimpleModel> 
</modules> 
<global> 

    <models> 
    <simplemodel> 
    <class>Ajzele_SimpleModel_Model</class> 
    <resourceModel>simplemodel_mysql4</resourceModel>  
    </simplemodel> 

    <simplemodel_mysql4> 
    <class>Ajzele_SimpleModel_Model_Mysql4</class> 
     <entities> 
      <simplemodel> 
        <table>simplemodel</table> 
      </simplemodel> 
     </entities>     
    </simplemodel_mysql4> 

</models> 

<resources> 
     <simplemodel_setup> 
      <setup> 
       <module>Ajzele_SimpleModel</module> 
     <class>Ajzele_SimpleModel_Model_Mysql4_Setup</class> 
      </setup> 

      <connection> 
       <use>core_setup</use> 
      </connection> 

     </simplemodel_setup> 

     <simplemodel_read> 
      <connection> 
       <use>core_read</use> 
      </connection> 
     </simplemodel_read> 

     <simplemodel_write> 
      <connection> 
       <use>core_write</use> 
      </connection> 
     </simplemodel_write> 

</resources>   
</global>  
    </config> 

而且我的模型文件結構

Model 
    SimpleModel.php 
    Mysql4 
     SimpleModel.php 
     Setup.php 
     SimpleModel 
      Collection.php 

這裏是我的SQL/simplemodel_setup /考覈的內容mysql4安裝,0.0.1.php

 <?php 

    $installer = $this; 

    $installer->startSetup(); 

    $baseTableName = 'simplemodel'; 

    $sql = " 
    SET FOREIGN_KEY_CHECKS=0; 
    -- ---------------------------- 
    -- Table structure for `simplemodel` 
    -- ---------------------------- 
    DROP TABLE IF EXISTS {$this->getTable($baseTableName)}; 
    CREATE TABLE {$this->getTable($baseTableName)} (
    `simplemodel_id` int(11) NOT NULL AUTO_INCREMENT, 
    `field1` varchar(255) DEFAULT NULL, 
    `field2` varchar(255) DEFAULT NULL, 
    PRIMARY KEY (`simplemodel_id`) 
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 
    "; 

    $installer->run($sql); 

    $installer->endSetup(); 

我已經嘗試了各種調試方法,但我沒有得到任何異常,也沒有發生錯誤。我應該怎麼做才能讓我的表格真正顯示在數據庫中?

+0

這裏沒有足夠的信息。我們至少需要你的'sql /'文件夾的內容。 – Nick 2012-01-05 17:46:25

+0

我編輯了這個問題。請看看,讓我知道如果有幫助。 – ivn 2012-01-05 18:02:35

+0

刪除'core_resource'表中的條目以使安裝腳本再次運行。 – clockworkgeek 2012-01-05 18:19:09

回答

2

我建議您將Magento置於開發人員模式並調試XML的跟蹤以檢查XML。要以開發人員模式配置Magento,您應該將變量MAGE_IS_DEVELOPER_MODE放置在虛擬主機的定義中或Magento根的.htaccess中。 例如DE虛擬主機:

<VirtualHost *:80> 
    DocumentRoot "C:\Program Files\Zend\Apache2/htdocs/local.pruebas.com" 
    ServerName local.pruebas.com 
    DirectoryIndex index.html index.php index.htm 
    SetEnv MAGE_IS_DEVELOPER_MODE "1"  
    <Directory "C:\Program Files\Zend\Apache2/htdocs/local.pruebas.com"> 
     AllowOverride All 
     Options All 
     Order allow,deny 
     Allow from all 
    </Directory> 

後,你應該修改的index.php在第66行,並把

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { 
Varien_Profiler::enable(); 
    Mage::setIsDeveloperMode(true); 
    ini_set('display_errors', 1); 
} 

Varien_Profiler ::啓用();和ini_set('display_errors',1);沒有條件,我認爲是錯誤的。 現在,您無法看到XML中有錯誤的simplexml_load_string()錯誤:

警告:simplexml_load_string()[function.simplexml-load-string]:實體:第4行:解析器錯誤:錯誤解析用C屬性名稱:\ Program Files文件\ Zend的\ Apache2的\ htdocs中\ local.pruebas.com \ LIB \瓦瑞恩\ SimpleXML的\ config.php文件上線510 ......

那麼,它的時間來調試 1.首先:去應用的/ etc/Ajzele_SimpleModel和力量,錯誤,例如:

<config> 
    <modules> 
     <Ajzele_SimpleModel <!--remove a '>' to force an error--> 
      <active>true</active> 
      <codePool>local</codePool> 
     </Ajzele_SimpleModel> 
    </modules> 
</config> 

你應該看到的錯誤。

2。第二:去應用程序/代碼/本地/ Ajzele/SimpleModel的/ etc/config.xml文件,然後重試過程

<config> 
    <modules> 
     <Ajzele_SimpleModel <!-- remove a '>' to verify that you load correctly your extension 
      <version>0.0.1</version> 
     </Ajzele_SimpleModel> 
    </modules> 
    <global> 

     <models> 
      <simplemodel> 
       <class>Ajzele_SimpleModel_Model</class> 
        <resourceModel>simplemodel_mysql4</resourceModel>  
      </simplemodel> 
     </models> 
    </global> 
</config> 

如果你沒有必要在這一點上你正確鴕鳥政策加載你的擴展簡單的XML錯誤,下一步是調試和調試config.xml

這不是具體的答案,但我認爲你可以看到與此解決方案。 謝謝,對不起,我inglish

+0

試過我們的調試方法,但它只是說它找不到我的當我的腳本在sql/simplemodel_setup文件夾中正確時,安裝程​​序腳本。有關爲什麼找不到我的安裝程序腳本的任何想法? – ivn 2012-01-06 10:04:14

+0

您使用Magento 1.6.1 rigth? – davidselo 2012-01-06 15:01:22

+0

是的1.6.1 .. – ivn 2012-01-06 15:09:40

0

我用你的結構創建了一個簡單模塊,並且setup資源腳本正確運行。您可以看到該模塊here。對比你的模塊,一旦你在安裝腳本中引發異常,開始逐行調試你的SQL。

+0

我嘗試了一行一行地調試我的SQL,並且還在MySQL查詢窗口中運行了sql查詢跑得很好。我認爲它只是因爲某種原因,無法找到我的安裝程序腳本,每當我第一次運行我的模塊時都會發生這種情況。在創建新表之前是否有任何特定步驟遺漏? – ivn 2012-01-06 10:17:04

+0

我跟着你的文章http://alanstorm.com/magento_setup_resources,每一件事都很好,直到你檢查升級腳本是否運行正常。我從來沒有收到'正在運行升級.....'的信息 – ivn 2012-01-06 16:59:06

+0

另外,如果我然後手動刪除core_resource表中的行,然後添加實際的'CREATE table'腳本並重新加載頁面,我不斷收到錯誤頁面。直到我去手動添加行。但是,我的桌子沒有出現 – ivn 2012-01-06 17:00:13

0

在您的安裝腳本的頂部放置一個die(__FILE__);語句,將您的模塊的行從core_resources中刪除,rm -rf var/cache/mage - *然後在瀏覽器中訪問您的網站,您應該獲得文件名你的文件。如果你確實刪除死亡陳述,你應該很樂意去。

我的猜測是,當你的文件不包含代碼來創建表時,Magento會運行升級。一旦版本在core_resources中增加,安裝腳本將不會重新運行。

+0

我試過把你的死(__ FILE__);並從模塊中刪除行,但我只是得到一個錯誤頁面,其中的報告說它找不到我的simplemodel_setup。 – ivn 2012-01-06 10:18:15

+0

您的安裝類是否具有Ajzele_SimpleModel_Model_Mysql4_Setup的類名,並位於app/code/local/Ajzele/SimpleModel/Model/Mysql4/Setup.php中? – 2012-01-06 10:57:45

+0

是的,它有正確的課程名稱和正確的位置。我想知道如何開始創建一個模塊n,然後再一步一步地使用不同的模塊名稱。只是爲了確保我不會錯過任何事情。並會將Setup.php強制創建呢? – ivn 2012-01-06 11:16:14

1

你可以嘗試用這種方式來定義:

<resources> 
     <selo_modulo1_setup> 
      <setup> 
       <module>Selo_Modulo1</module> 
      </setup> 
     </selo_modulo1_setup> 
    </resources> 

後來又放在yourmodule/SQL/selo_modulo1_setup /安裝-1.6.0.0.php,並安裝的例子腳本:

<?php 
die('All right'); 

/* @var $installer Mage_Core_Model_Resource_Setup */ 
$installer = $this; 
$installer->startSetup(); 
/** 
* Create table 'poll' 
*/ 
$table = $installer->getConnection() 
    ->newTable($installer->getTable('selo_modulo1/blog_post')) 
    ->addColumn('post_id', Varien_Db_Ddl_Table::TYPE_INTEGER, null, array(
     'identity' => true, 
     'unsigned' => true, 
     'nullable' => false, 
     'primary' => true, 
     ), 'Post Id') 
    ->addColumn('title', Varien_Db_Ddl_Table::TYPE_TEXT, 255, array(
     ), 'Post title') 
    ->addColumn('content', Varien_Db_Ddl_Table::TYPE_TEXT, 1024, array(
     ), 'Post content') 
    ->setComment('Blog_post');//Comentario de la tabla. 
$installer->getConnection()->createTable($table); 

$installer->endSetup(); 

而對於鴕鳥政策犯的錯誤我的協議作出擴展複製/粘貼代碼操作系統的核心和調整我使用了類似的模塊。

Regards david

+0

那麼只需要用你的代碼改變資源部分和安裝腳本?但是需要更改,因爲您提到的表名與我的不同? – ivn 2012-01-06 15:22:46

相關問題