【发布时间】:2014-05-09 06:20:08
【问题描述】:
您好,我刚刚开始学习 magento 模块开发,为此我正在关注 pierefay 教程,我发现这非常有用。但是我在第四步一步一步地遵循他的教程
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 文件中时,它会显示数据库中的条目列表。
谁能告诉我如何在块文件中使用此代码来返回数据
谢谢
【问题讨论】:
-
先检查集合是否返回任何东西
-
检查这是否返回任何东西 Mage::getModel('test/test')->getCollection()->addAttributeToSelect('*');
标签: magento zend-framework module block