我正在尝试为 Prestashop 1.4 构建一个模块,我需要检索并显示完整的类别和子类别列表,但我发现了一些困难:
这是我的模块逻辑:
class HyperFeed extends Module {
function __construct(){ blablabla }
public function install(){ blablabla }
public function _getCategories(){
$version_mask = explode('.', _PS_VERSION_, 3);
if ($version_mask[1]<5){$id_category=1;}else{$id_category=0;}
function getCategories($id_category){
$sql = 'SELECT '._DB_PREFIX_.'category.id_category,name,'._DB_PREFIX_.'category.level_depth,'._DB_PREFIX_.'category.id_parent FROM '._DB_PREFIX_.'category
INNER JOIN '._DB_PREFIX_.'category_lang ON '._DB_PREFIX_.'category_lang.id_category = '._DB_PREFIX_.'category.id_category
WHERE id_parent = '.$id_category.' AND id_lang = 3';
$contentTable = '<table>';
if ($results = Db::getInstance()->ExecuteS($sql)){
foreach ($results as $row){
$contentTable .= '
<tr>
<td width="3%"><input type="checkbox" name="footerBox[]" class="cmsBox" id="1_1" value="1_1"></td>
<td width="3%">'.$row['id_category'].'</td>
<td width="94%"><img style="vertical-align:middle;" src="../img/admin/lv1.gif" alt="">
<label for="1_1" class="t"><b>'.$row['name'].'</b></label></td>
</tr>';
getCategories($row['id_category']);
}
}
$contentTable .= '</table>';
}
getCategories(1);
$this->_html .= $contentTable;
}
public function getContent(){
$this->_html .='<form>blablabla';
$this->_getCategories();
$this->_html .='blablabla</form>';
}
return $this->_html;
}
我得到的只是一个“未定义的变量:contentTable”,我做错了什么?
提前致谢