2016-06-23 53 views
1

我正在創建一個控制器到模塊文件夾,我的模塊文件夾名稱是「productarticle」,我的控制器文件「AdminProductarticleController.php」存在路徑:「productarticle/controllers/admin」中。PrestaShop管理模塊控制器未找到

控制器的代碼如下所述:

class AdminProductarticleController extends ModuleAdminController 
{ 
    public function __construct() 
    { 
     echo Tools::getValue('id_product'); 
    } 
} 

,我試圖通過以下網址訪問此控制器:

http://myshost/admin/index.php?fc=module&module=productarticle&controller=AdminProductarticle&id_product=1&token=mytoken 

但是,通過使用顯示下面的錯誤上述網址:

enter image description here

請告訴我,如果我是在這裏做錯了什麼。

在此先感謝。

回答

1

每當發生這種情況是因爲我沒有爲我的新控制器創建菜單項。

我建議你做的是去管理>菜單,然後創建一個新的條目。

填寫這樣的形式:

Name: Productarticle 
Class: AdminProductarticle 
Module: productarticle (if that's the name you gave your module) 
Active: NO (this way you don't have to have a menu entry that's gonna be useless to you) 

最重要的是,你應該有這樣的事情在你__construct()

class AdminProductarticleController extends ModuleAdminController 
{ 
    public function __construct() 
    { 
     $this->module = 'productarticle'; //refers to your module's $this->name = 'productarticle'; 
     $this->bootstrap = true; 
     $this->context = Context::getContext(); 
     //The following 2 lines are useful if you have to link your controller to a certain table for data grids 
     $this->table = 'contribution'; 
     $this->className = 'Contribution'; 

     parent::__construct(); 
    } 
} 

從這時開始一切都應該罰款。

+0

謝謝,你的建議對我有用。 –

+0

很高興我能幫上忙。這些文檔缺乏模塊開發的一些核心方面,你必須嘗試一下,在遠程網站上搜索甚至鑽研Core來找出答案。我覺得很傷心。 –

+0

@JulienLachal我認爲你不需要這條線「$ this-> context = Context :: getContext();」 –