Search code examples
phpprestashop

PrestaShop Admin Module Controller Not Found


I am creating a controller into module folder and my module folder name is "productarticle" and my controller file "AdminProductarticleController.php" exist into path: "productarticle/controllers/admin".

The code of controller is mentioned below:

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

And I am trying to access this controller by using below URL:

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

But by using aforesaid URL showing below error:

enter image description here

Please tell me if I am doing anything wrong here.

Thanks in advance.


Solution

  • Whenever this happened to me was because I hadn't created a menu entry for my new controller.

    What I'd advise you to do is to go to Administration > Menus then created a new entry.

    Fill in the form like this :

    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)  
    

    On top of that you should have something like this in your __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();
        }   
    }
    

    From this point onwards everything should be fine.