2014-05-09 61 views
0

嗨,我剛開始學習magento模塊開發,爲此我遵循pierefay教程,我發現這非常有用。但是我下面他的教程一步一步在第四步塊沒有返回任何模塊開發Magento

http://www.pierrefay.com/magento-model-database-tutorial-54#comment-1507

我得到了塊文件停留在一個地方 我有以下代碼,並建議它將從數據庫返回的條目

<?php 
class Pfay_Test_Block_Monblock extends Mage_Core_Block_Template 
{ 
    public function methodblock() 
    { 
     //on initialize la variable 
     $retour=''; 
     /* we are doing the query to select all elements of the pfay_test table (thanks to our model test/test and we sort them by id_pfay_test */ 
    $collection = Mage::getModel('test/test')->getCollection()->setOrder('id_pfay_test','asc'); 

     /* then, we check the result of the query and with the function getData() */ 
     foreach($collection as $data) 
     { 
      echo $retour .= $data->getData('nom').' '.$data->getData('prenom') 
        .' '.$data->getData('telephone').'<br />'; 
     } 
     //i return a success message to the user thanks to the Session. 
     Mage::getSingleton('core/session')->addSuccess($retour); 
     print_r($retour); 
     } 
} 

但它沒有返回任何東西。 當我將這段代碼複製到我的indexcontroller或phtml文件中時,它會顯示數據庫中的條目列表。

誰能告訴我怎麼可以在塊文件中使用此代碼返回數據

感謝

+0

首先檢查收集是否返回任何東西 – Slimshadddyyy

+0

檢查是否返回任何東西Mage :: getModel('test/test') - > getCollection() - > addAttributeToSelect('*'); –

回答

0

確定我在PHTML文件調用

<?php 
    echo $this->methodblock(); 
?> 

得到了解決