Jump to content

Module creation : error "Controller not found"


Recommended Posts

Hello

 

I continue my learning modules creation for Presta 1.6. 

 

I just created a minimalist test module with the following structure:

  • testmodule
    • controllers
      • admin
        • test.php
          (class testmoduleTestAdminController extends ModuleAdminController)
  • testmodule.php
    (class testModule extends Module)
 
testmodule.php
class testModule extends Module
{
    public function __construct()
    {
        $this->name = 'testmodule';
        $this->tab = 'administration';
        $this->need_instance = 1;

        parent::__construct();

        $this->displayName = $this->l('Test Module');
        $this->description = $this->l('Juste un test sur les contrôleurs');

        $this->version = '1.0.0';
        $this->author = 'Besens';
    }

    public function install()
    {
        return parent::install();
 	  }

    public function uninstall()
    {
        return parent::uninstall();
    }

test.php

class testmoduleTestAdminController extends ModuleAdminController
{
    public function __construct()
    {
      parent::__construct();
    }

    public function initContent()
    {
      parent::initContent();
    }

    public function display()
    {
        parent::display();
    }
}
The installation is successful. Then I try to call test.php controller like this:
http://monsite.dev/monadmin/index.php?module=testmodule&controller=test

But on display admin page I have the error "Controller not found".

 

Please help me to understand why.

 

Thanks in advance

 

 

Link to comment
Share on other sites

You need a Token that is generated by PS

 

My link looks like: ?controller=AdminPhotoOrder&token=ed948e9517be7b47eede109cf9f25698 (only the controler and the token)

As far as I know, this things are the only one that you need.

 

Try this code in your testModule:


/*** To call when the module is installing
*
* @return bool The module was installed correctly
*/
  public function install()
  {
    // Install Tabs
    $tab = new Tab();


    foreach (Language::getLanguages() as $language) {
        $tab->name[$language['id_lang']] = 'My Module';
    }
    
    $tab->class_name = 'testModule';
    $tab->module = $this->name;

    $tab->id_parent = (int)Tab::getIdFromClassName('AdminCustomers');

    return true;
}
 

Then, you wil have a link in your backoffice, under Customers. Fron there, you can enter.

 

I edit the message, because the editor is a devil...  :angry:

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

I tried with the Token but no effect.

 

I uninstalled my module. I deleted the cache/class_index.php and I added your code in my install function and installed again my module, but nothing more.

 

How I can debug that ? I don't understand...

Link to comment
Share on other sites

This is my ddd($tab) just befor return in the install() function :

Tab Object
(
    [name] => Array
        (
            [1] => My Module
        )

    [class_name] => testModule
    [module] => testmodule
    [id_parent] => 37
    [position] => 
    [active] => 1
    [hide_host_mode] => 
    [id] => 
    [id_lang:protected] => 
    [id_shop:protected] => 
    [id_shop_list] => 
    [get_shop_from_context:protected] => 1
    [table:protected] => tab
    [identifier:protected] => id_tab
    [fieldsRequired:protected] => Array
        (
            [0] => class_name
        )

    [fieldsSize:protected] => Array
        (
            [module] => 64
            [class_name] => 64
        )

    [fieldsValidate:protected] => Array
        (
            [id_parent] => isInt
            [position] => isUnsignedInt
            [module] => isTabName
            [active] => isBool
            [hide_host_mode] => isBool
        )

    [fieldsRequiredLang:protected] => Array
        (
            [0] => name
        )

    [fieldsSizeLang:protected] => Array
        (
            [name] => 64
        )

    [fieldsValidateLang:protected] => Array
        (
            [name] => isTabName
        )

    [tables:protected] => Array
        (
        )

    [webserviceParameters:protected] => Array
        (
        )

    [image_dir:protected] => 
    [image_format:protected] => jpg
    [def:protected] => Array
        (
            [table] => tab
            [primary] => id_tab
            [multilang] => 1
            [fields] => Array
                (
                    [id_parent] => Array
                        (
                            [type] => 1
                            [validate] => isInt
                        )

                    [position] => Array
                        (
                            [type] => 1
                            [validate] => isUnsignedInt
                        )

                    [module] => Array
                        (
                            [type] => 3
                            [validate] => isTabName
                            [size] => 64
                        )

                    [class_name] => Array
                        (
                            [type] => 3
                            [required] => 1
                            [size] => 64
                        )

                    [active] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [hide_host_mode] => Array
                        (
                            [type] => 2
                            [validate] => isBool
                        )

                    [name] => Array
                        (
                            [type] => 3
                            [lang] => 1
                            [required] => 1
                            [validate] => isTabName
                            [size] => 64
                        )

                )

            [classname] => Tab
            [associations] => Array
                (
                    [l] => Array
                        (
                            [type] => 2
                            [field] => id_tab
                            [foreign_field] => id_tab
                        )

                )

        )

    [update_fields:protected] => 
    [force_id] => 
)

END
Link to comment
Share on other sites

I renamed my controller like that :

 

/controllers/admin/test.php en /controllers/admin/AdminTestmoduleController.php

 

And : class AdminTestmoduleController extends ModuleAdminController

 

Then I made some modifications on the module class install function :

public function install()
{
  // Install Tabs
  $tab = new Tab();

  foreach (Language::getLanguages() as $language) {
    $tab->name[$language['id_lang']] = 'My Module';
  }

  $tab->class_name = 'AdminTestmodule'; // <-- NEW : My controller name in controllers/admin
  $tab->module = $this->name;

  $idParent = (int)Tab::getIdFromClassName('AdminParentCustomer'); // <-- NEW : AdminParentCustomer
  $tab->id_parent = $idParent;
  $tab->position = Tab::getNbTabs($idParent); // <-- NEW

  if(!$tab->save()) // <-- NEW
      return false;

  Configuration::updateValue('MYMODULE_ADMIN_TAB', $tab->id); // <-- NEW

  return parent::install();
}

And now it's OK via the menu.

 

I can call my controller with : 

http://monsite.dev/monadmin/index.php?controller=Myetickets&token=XXXX

Thanks a lot for your help :-)

Edited by Besens (see edit history)
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...