0
votes

I was able to create a menu tab in the back office but when I click on it, I get Page not found. The controller is missing or invalid.

Here's the code for my controller -

<?php

class AdminModuleNameConvert extends ModuleAdminController {


    public function __construct()   {
        $this->bootstrap = true;
        parent::__construct();
    }
}

Using the solution provided by ethercreation, I get the controller to load, but it shows me

Invalid security token

2

2 Answers

1
votes

Try width :

In your module : modulenameconverter

class modulenameconverter extends Module
{
    public function __construct(Context $context = null)
    {
        $this->name = 'modulenameconverter';
        $this->version = '1';
        $this->bootstrap = true;
        $this->author = 'Stackoverflow';
        $this->displayName = $this->l('modulenameconverter');
        $this->description = $this->l('Module name converter');
        
        parent::__construct();
    }

    public function install()
    {
        $tab = new Tab();
        $tab->class_name = 'Adminmodulenameconverter';
        $tab->module = 'modulenameconverter';
        $tab->name[1] = 'modulenameconverter';
        $tab->id_parent = 2;
        $tab->active = 1;
        if (!$tab->save()) {
            return false;
        }
        return parent::install();
    }

    public function uninstall()
    {
        $id_tab = (int)Tab::getIdFromClassName('Adminmodulenameconverter');
        $tab = new Tab($id_tab);

        if (Validate::isLoadedObject($tab)) {
            if (!$tab->delete()) {
                return false;
            }
        } else {
            return false;
        }
        return parent::uninstall();
    }
}

In module/controllers/admin/AdminModulenameconverterController.php

class AdminNameconverterController extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();
        $this->bootstrap = true;
        $this->id_lang = $this->context->language->id;
        $this->default_form_language = $this->context->language->id;
    }

    public function initContent()
    {
        parent::initContent();
    } 
}
-1
votes

I was having the exact same issue and it appears that I was not configuring the tab parameters correctly... I was trying to pass an array for the "$this->module" parameter so Prestashop could not find the module because in the database, the module linked to the tab was equal to ""...

So my best advice in this case is to always check your database fields to see if they are correctly filled.

To conclude : It's always the silliest issues that makes the biggest headaches... -_-'