Jump to content

Unable to create an admin controller


Recommended Posts

Hello, Im trying to create my adminModuleController in Prestashop 1.7.4. Response : Not found

 

Code:

In install():

        return parent::install() &&
            $this->registerHook('header') &&
            $this->createTab() &&
            $this->registerHook('backOfficeHeader');

When I create tab

    public function createTab(){
        $invisible_tab = new Tab();
        $invisible_tab->active = 1;
        $invisible_tab->class_name = 'AdminTeinorUltraBanner';
        $invisible_tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
            $invisible_tab->name[$lang['id_lang']] = $this->l('A name which is never shown');
        }
        $invisible_tab->id_parent = -1;
        $invisible_tab->module = $this->name;
        $invisible_tab->add();
        return true;
    }

When I try to get Controller Link

          Context::getContext()->link->getAdminLink('AdminTeinorUltraBanner')

 

Controller code:

 

<?php
class AdminTeinorUltraBannerController extends ModuleAdminController
{
  public function __construct()
{
    $this->bootstrap = true;
    $this->table         = 'AdminTeinorUltraBanner';
    $this->className     = 'AdminTeinorUltraBanner';
    parent::__construct();

    }
}

 

 

 

Link to comment
Share on other sites

Do you have debug mode on? Any errors?

In your createTab function don't just return true, make it "return $invisible_tab->add();". This way you know if tab is created.

If I remember correctly though, you can't use $this->l function during install, since the module isn't installed yet. Just use a fixed text for the tab name, since it isn't going to be used anyway. This might be why your tab creation is failing, but you never notice it because the function is always return true so the module installs without any errors.

Link to comment
Share on other sites

  • [object Object] changed the title to Unable to create an admin controller

class AdminCotizadorController extends ModuleAdminController
{
    public $path = 'modules/cotizador/views/';
    public function __construct()
    {
        $this->bootstrap = true;
        parent::__construct();
    }

    public function initContent()
    {
        parent::initContent();
		/*template_dir is setted at module main php $this->template_dir = '../../../../modules/'.$this->name.'/views/templates/admin/';*/
        $this->setTemplate($this->module->template_dir . 'admin.tpl');
    }

This is my PHP Code, path is /modulename/controllers/admin/AdminModuleName.php and installTab method, I hope can I help you

public function installTab()
    {
        $tab = new Tab();
        $tab->active = 1;
		//PHP admin controller name 
        $tab->class_name = "AdminCotizador";
        $tab->name = array();
		//Set the icon at Admin Dashboard
        $tab->icon = 'aspect_ratio';
        foreach (Language::getLanguages(true) as $lang) {
            $tab->name[$lang['id_lang']] = "Cotizaciones";
        }
        $tab->id_parent = 2;
        $tab->position = 6;
        $tab->module = $this->name;
        return $tab->add();
    }

 

Edited by PMunoz92 (see edit history)
Link to comment
Share on other sites

  • 1 year later...

Hi,

 

Lo que te falte hacer seguramente es "reinicializar" el módulo desde el backoffice.... despues de hacerlo me ha funcionado, he tomado como guia el módulo:

blockreassurance -> controllers -> admin -> AdminBlockListingController.php

 

Si te fijas en el nombre del fichero no importa que no aparezca el nombre del módulo, lo que si debe coincidir es el nombre del fichero con el de la clase,

class AdminBlockListingController extends ModuleAdminController

 

Para llegar a esta conclusión he renombrado el controlador y la clase y no funcionaba... solo despues de reinicializar el módulo es que lo toma en cuenta como URL nueva,

 

 

Espero os sirva,

 

 

Saludos!!

 

  • Thanks 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...