我正在尝试为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”,我做错了什么?
提前致谢
答案 0 :(得分:1)
您的$contentTable
定义在getCategories()
内,而不是_getCategories()
。
因此,在以下几行中,它被认为没有定义。
getCategories(1);
$this->_html .= $contentTable;
您可以尝试执行以下操作:
查找
$contentTable .= '</table>';
替换为:
$contentTable .= '</table>';
return $contentTable;
查找
getCategories(1);
$this->_html .= $contentTable;
替换为:
$contentTable = getCategories(1);
$this->_html .= $contentTable;
这应该通过从getCategories()函数返回并分配_getCategories()
变量来正确定义$contentTable
函数中的变量。
答案 1 :(得分:0)
我找到了别的东西
public static function getCategoryTree($id_product,$id_lang){
$root = Category::getRootCategory();
$selected_cat = Product::getProductCategoriesFull($id_product, $id_lang);
$tab_root = array('id_category' => $root->id, 'name' => $root->name);
$helper = new Helper();
$category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true);
return $category_tree;
}
$这 - &GT; getCategoryTree(NULL,$ id_lang); 并且您将类别树作为prestashop backoffice关联选项卡。 将$ id_product替换为null,并将检查产品类别。 希望我能帮忙 抱歉我的英语不好我是法国人