0

は私のadminControllerクラス内の.tplファイルと相互作用し、私はそれをしようとすると、このエラーが表示されますAdminControllerにtplを含めるにはどのような方法が適していますか?私は必要

Fatal error: Call to undefined method RiddlePageController::getCacheId() in /home/USER/public_html/prestashop/modules/RiddleModule/controllers/admin/RiddlePage.php on line 48

これは私の管理コントローラのコードです:

class RiddlePageController extends AdminController { 

public function __construct() 
{ 
    $this->html = ''; 
    $this->display = 'view'; 
    $this->meta_title = $this->l('metatitle'); 
    $this->module = "RiddleModule"; 

    parent::__construct(); 
} 

public function initContent() 
{ 
    $this->postProcess(); 
    $this->show_toolbar = true; 
    $this->display = 'view'; 
    $this->meta_title = $this->l('Modulo'); 
    parent::initContent(); 
} 

public function initToolBarTitle() 
{ 
    $this->toolbar_title = $this->l('Titulo'); 
} 

public function initToolBar() 
{ 
    return true; 
} 

public function renderView() { 
    $this->context->smarty->assign(
     array( 
      'img1' => "http://www.free-3dmodels.com/image/Flowers-3D-Model-3662994d.png", 
      'img2' => "http://www.all3dmodel.com/Images/39.jpg" 
      ) 
     ); 
    // in return have error "getCacheId" 
    return $this->display(__FILE__, 'content.tpl', $this->getCacheId()); 
    // return "<b>This works fine!!</b>"; 

} 

私のTPLファイル試験のためには{$img1}{$img2}しかありません。

私はすべて間違っているかもしれませんが、これは自分の管理ページで行う最良の方法ではありません。

答えて

0

は、答えは$this->context->smarty->fetch(location)を使用しているが、ないrenderListではなく、renderViewのreturn文でOKですし、TPLファイルを取得し、正しくロードさPrestaShopのスマート変数。例:

public function renderView(){ 
    $this->context->smarty->assign(
     array( 
      'img1' => "http://www.free-3dmodels.com/image/Flowers-3D-Model-3662994d.png", 
      'img2' => "http://www.all3dmodel.com/Images/39.jpg" 
      ) 
     ); 

    return $this->context->smarty->fetch(_PS_MODULE_DIR_ . "RiddleModule/controllers/front/prueba.tpl"); 
} 

ファイルの場所は

0

AdminControllerクラスには、TPLをレンダリングするために使用するdisplayメソッドの実装がありません。

あなたは、設定されたモジュールVAR後にこのようなものを使用することができます。

$this->module->display(_PS_MODULE_DIR_.$this->module->name.DIRECTORY_SEPARATOR.$this->module->name.'.php', 'content.tpl') 

幸運。

4

AdminControllerクラスにgetCacheIdメソッドがないためにエラーが発生しました。

あなたの質問に答えるには、少し修正する必要があります。

まず(AdminControllerModuleAdminController拡張しません):次に

 
class AdminRiddlePageController extends ModuleAdminController 
{ 
}

、カスタムTPLを表示したい場合は、中view.tplファイルを配置します。
prestashop/modules/RiddleModule/views/templates/admin/riddlepage/helpers/view/
または prestashop/modules/RiddleModule/views/templates/admin/riddle_page/helpers/view/

(私はドン」アンダースコアが必要な場合は覚えておいてください)

renderView方法は次のようにする必要があります:@TheDrotは私たちに語ったよう

public function renderView() 
{ 
    /* Your code */ 

    /* Use this snippet to assign vars to smarty */ 
    $this->tpl_view_vars = array(
     'myvar' => 1, 
     'secondvar' => true 
    ) 
    return parent::renderView(); 
} 
+0

それは私の友人が動作しません。この場合にはTPLファイルをロードすることは重要ではありません...しかし、良いニュースは、今、あなたのソリューションであり、空白ページを表示のみ、エラーはない...私はあなたを見せてみましょうhttp://prnt.sc/dy8bp5 – manhattan

+1

@マンハッタン[This(http://stackoverflow.com/questions/40544689/render-helper-form-from-prestashop-admin -controller /)は管理コントローラにカスタムtplをロードする方法を助けます。 – TheDrot

+0

@manhattan私は変更を加えて、 'RiddlePageController'の代わりに' AdminRiddlePageController'を試してみましたが、DBの 'tab'テーブルを更新するのを忘れないでください。 – sarcom

関連する問題