我有一个custome模块允许从后端向sql添加自定义记录并进行编辑。
如何调用forntend视图块的下拉列表。
管理员中的简单记录视图网格:
ID Title Value
1 name1 value1
2 name2 value2
在视图中有:
<?php echo Mage::getModel('module/block')->getSelectBox(); ?>
在Model文件夹中有函数:
public function getSelectBox(){
return 'test';
}
此函数中的调用下拉列表如何从后端选择所有记录?
答案 0 :(得分:1)
使用集合。您可以通过这种方式获取所有值。
$coll = Mage::getModel('module/block')->getCollection();
foreach($coll as $value){
print_r($value->getData());
}
使用getSelectBox返回title =&gt; value
的数组public function getSelectBox(){
$coll = $this->getCollection();
$response = array();
foreach($coll as $value){
$response[$value->getTitle()]=$value->getValue();
}
return $response;
}