PrestaShop:如何在控制器内加载控制器?

时间:2016-08-27 08:12:49

标签: php prestashop

如何在控制器prestashop中加载控件? Opencart支持控制器内的负载控制器

$data['efgh'] = $this->load->controller('abcd/efgh');

那么支持它的prestashop?如果是,那么如何?

我有一个控制器类别渲染自定义tpl

public function renderList(){

    $tpl = $this->createTemplate('dashboard.tpl');

    // Category
    $categories = GenCategory::getCategories();
    $public_categories = GenCategory::getPublicCategories();
    $unpublic_categories = GenCategory::getUnpublicCategories();

    $tpl->assign(array(
        // Category
        'categories' => $categories,
        'public_categories' => $public_categories,
        'unpublic_categories' => $unpublic_categories,
    ));
    return $tpl->fetch();
}

和控制器菜单呈现自定义tpl

public function renderList(){

    $tpl = $this->createTemplate('menu.tpl');

    $menu = GenMenu::getMenu();

    $tpl->assign(array(
        'menu' => $menu,
    ));
    return $tpl->fetch();
}

我需要在分类中显示菜单。

1 个答案:

答案 0 :(得分:1)

我建议您以这种方式使用initContent()方法,而不是renderList:

public function initContent(){
    // Category
    $categories = GenCategory::getCategories();
    $public_categories = GenCategory::getPublicCategories();
    $unpublic_categories = GenCategory::getUnpublicCategories();

    // Menu
    $menu = $this->genMenu();

    $this->context->smarty->assign(array(
        // Category
        'categories' => $categories,
        'public_categories' => $public_categories,
        'unpublic_categories' => $unpublic_categories,
        // Menu
        'menu' => $menu
    ))
    $this->setTemplate(`rightdirectoryofyourtpl`.'dashboard.tpl');
}

public function genMenu(){
    $menu = GenMenu::getMenu();

    $this->context->smarty->assign(array(
        'menu' => $menu,
    ));
    return $this->context->smarty->fetch(`directoryofyourtpl`/menu.tpl)
}

然后在你的tpl中只需'打印'$ menu var