2017-08-22 37 views
0

大家好我正在爲Prestashop 1.6編寫一個高級搜索模塊,該模塊查找產品和一些自定義表格中加載的其他功能之間的關聯。Prestshop 1.6模塊自定義搜索視圖

我寫過一個ModuleFrontController,表單提交後必須返回結果頁面,但視圖沒有基本佈局。

裏面的initContent()方法我把這個功能寫在Official documentation

$this->setTemplate('advanced-search.tpl'); 

但只顯示產品列表,沒有別的,沒有頁眉,頁腳不,沒有側邊欄...

這是我的代碼:

class MyModuleSearchModuleFrontController extends ModuleFrontController 
{ 

    protected static $config_post_submit_values = ['action']; 

    public function initContent() 
    { 

     parent::initContent(); 

     switch (Tools::getValue($this->getPostSubmitValue())) { 
      // Filter action 
      case 'filter_1': 
      /* 
      * DO STUFF TO RETRIEVE PRODUCTS 
      */ 
      case 'filter_2': 
      /* 
      * DO STUFF TO RETRIEVE PRODUCTS 
      */ 
      default: 
       $products = []; 
     } 

     $this->smarty->assign(['products' => $products]); 

     $this->setTemplate('advanced-search.tpl'); 
    } 

    /** 
    * Get the action submited from the configuration page 
    * @return string 
    */ 
    protected function getPostSubmitValue() 
    { 
     foreach (self::$config_post_submit_values as $value) { 
      if (Tools::isSubmit($value)) { 
       return $value; 
      } 
     } 

     return false; 
    } 

} 

在此先感謝您的幫助!

回答

0

我認爲問題是你不能訪問smarty,因爲這個對象是在context對象中。

所以

$this->smarty->assign(['products' => $products]); 

應該

$this->context->smarty->assign(['products' => $products]); 

旁註

打開錯誤日誌,去/config/defines.inc.php和更改線路

define('_PS_MODE_DEV_', false); 

define('_PS_MODE_DEV_', true); 

不要_PS_MODE_DEV生產/生活環境轉。