我是Magento的新手,我正在尝试为自定义模块创建一个控制器。控制器代码是:
class Shopez_HomeSearch_IndexController extends Mage_Core_Controller_Front_Action
{
public function dothesearchAction()
{
$searchQuery = $this->getRequest()->getParam("param");
$_obj = new Varien_Data_Collection();
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);
umask(0);
Mage::app();
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "Select seller_id, store_title from marketplace_sellerprofile";
$_obj = $connection->fetchAll($sql);
var_dump($_obj);
foreach ($_obj as $_obj2):
var_dump($_obj2->getData());
//do something else once you get the data out of obj2
endforeach;
}
}
来自查询的转储完全正常但是当我尝试使用foreach来获取单个字段值时,我收到上述错误。
var_dump($ _ obj)输出如下:
array (size=37)
0 =>
array (size=2)
'seller_id' => string '1' (length=1)
'store_title' => string 'The Goodness Store' (length=18)
1 =>
array (size=2)
'seller_id' => string '2' (length=1)
'store_title' => string 'XYZ Store' (length=22)
....
答案 0 :(得分:1)
当您在magento上使用直接查询时,您将无法使用getData()函数。您试图以数组格式获取数据而不是对象。因此,您可以访问以下数据。
foreach ($_obj as $_obj2):
var_dump($_obj2['seller_id']);
var_dump($_obj2['store_title']);
endforeach;