Jump to content

Modules admin controller not found


PhpMadman

Recommended Posts

In my module I added /controllers/admin/AdminRenderPdf.php

And then I added this.

<?php
class AdminRenderPdf extends ModuleAdminController
{
    public function __construct()
    {
        parent::__construct();
    }

}

?>

But PrestaShop refuses to find it. Even when I re-install the module and deleted the class_index.php

What else do I need to do?

Link to comment
Share on other sites

If it helps, I'm also doing a module that affects that file...

 

I've just put an AdminPdfController.php in the module's /modules/my-module/override/controllers/admin/ folder.

 

This starts

class AdminPdfController extends AdminPdfControllerCore
which seems to work.

 

Not quite the same thing, but might help??

Edited by irrelevant (see edit history)
  • Like 1
Link to comment
Share on other sites

It seems to work... If you call it with e.g.

	Tools::redirectAdmin($this->context->link->getAdminLink('AdminPdf').'&submitAction=generateMyModule&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')));
(c.f. AdminDeliverySlipController.php)

 

Then all your override needs to do is add a function

	public function processGenerateMyModule()
- no need to actually amend anything existing - it gets found automatically. (but note the capitalisation of the G!)
Link to comment
Share on other sites

Hi.

 

Maybe I was a bit unclear. It's my new Admin Controller that does not work, from first post.

I have not tried with the override. I don't like to use overrides, not even for adding functions.

Even tho this module must use some overrides to work. I try to keep the code to a minimum.

 

But I might need to add the override anyway. I'm gonna sell it on addon site. So they might fail it due to that litle hack...

Yeah.. I think I'll rewrite it to use AdminPdfController override...

Link to comment
Share on other sites

Ah gotcha....

Not sure if it's the same as you need, but my module adds an admin controller ("AdminMyModuleController.php") using

class AdminMyModuleController extends ModuleAdminController
, which is then called from the Orders menu (created via

$this->installModuleTab('AdminMyModule', 'My Module', Tab::getIdFromClassName('AdminOrders'))
)
Link to comment
Share on other sites

  • 4 months later...

It looks like module admin controllers depend on tabs. So if you want to activate an admin controller you have to create a corresponding tab, and if you don't want it to be included in menu, you can just hide it by setting $tab->id_parent = -1

so, first you create a file here: /controllers/admin/AdminYourModuleNameSpecialControllerName.php

<?php
class AdminYourModuleNameSpecialControllerNameController extends ModuleAdminController
{
    public function __construct()
    {
         parent::__construct();
        // do your stuff here
    }	
}

Then you create a method for adding tab and run it on module install
Something like this: 

public function install()
{
    ...
    if (!parent::install() || !$this->addTab() ...)
        return false;
    return true;
}

public function addTab()
{
    $tab = new Tab();
    $tab->name = array();
    foreach (Language::getLanguages() as $language)
        $tab->name[$language['id_lang']] = 'AdminYourModuleNameSpecialControllerName';
    $tab->class_name = 'AdminYourModuleNameSpecialControllerName';        
    // if id_parent = -1, tab will not be visible in menu
    $tab->id_parent = -1;
    $tab->module = $this->name;
    if(!$tab->add())
        return false;
    return true;
}

 

This may not be the official way of activating an admin module controller, but I didn't find any documentation on this point, so I currently use this way and it works fine. 

Edited by Amazzing (see edit history)
  • Like 2
Link to comment
Share on other sites

  • 3 months later...

It looks like module admin controllers depend on tabs. So if you want to activate an admin controller you have to create a corresponding tab, and if you don't want it to be included in menu, you can just hide it by setting $tab->id_parent = -1

 

so, first you create a file here: /controllers/admin/AdminYourModuleNameSpecialControllerName.php

<?php
class AdminYourModuleNameSpecialControllerNameController extends ModuleAdminController
{
    public function __construct()
    {
         parent::__construct();
        // do your stuff here
    }	
}

Then you create a method for adding tab and run it on module install

Something like this: 

public function install()
{
    ...
    if (!parent::install() || !$this->addTab() ...)
        return false;
    return true;
}

public function addTab()
{
    $tab = new Tab();
    $tab->name = array();
    foreach (Language::getLanguages() as $language)
        $tab->name[$language['id_lang']] = 'AdminYourModuleNameSpecialControllerName';
    $tab->class_name = 'AdminYourModuleNameSpecialControllerName';        
    // if id_parent = -1, tab will not be visible in menu
    $tab->id_parent = -1;
    $tab->module = $this->name;
    if(!$tab->add())
        return false;
    return true;
}

 

This may not be the official way of activating an admin module controller, but I didn't find any documentation on this point, so I currently use this way and it works fine. 

At last, after a week of trying, a working example!

MANY thanks!

Link to comment
Share on other sites

  • 5 months later...

It looks like module admin controllers depend on tabs. So if you want to activate an admin controller you have to create a corresponding tab, and if you don't want it to be included in menu, you can just hide it by setting $tab->id_parent = -1

 

so, first you create a file here: /controllers/admin/AdminYourModuleNameSpecialControllerName.php

<?php
class AdminYourModuleNameSpecialControllerNameController extends ModuleAdminController
{
    public function __construct()
    {
         parent::__construct();
        // do your stuff here
    }	
}

Then you create a method for adding tab and run it on module install

Something like this: 

public function install()
{
    ...
    if (!parent::install() || !$this->addTab() ...)
        return false;
    return true;
}

public function addTab()
{
    $tab = new Tab();
    $tab->name = array();
    foreach (Language::getLanguages() as $language)
        $tab->name[$language['id_lang']] = 'AdminYourModuleNameSpecialControllerName';
    $tab->class_name = 'AdminYourModuleNameSpecialControllerName';        
    // if id_parent = -1, tab will not be visible in menu
    $tab->id_parent = -1;
    $tab->module = $this->name;
    if(!$tab->add())
        return false;
    return true;
}

 

This may not be the official way of activating an admin module controller, but I didn't find any documentation on this point, so I currently use this way and it works fine. 

This is still not working , tab is added but same error "controller not found". 

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...