Jump to content

Recommended Posts

Hello,

 

PS version 1.6.1.1

 

I need some help ; cannot figure out how to solve my problem.

 

Here it is : I have a new customized module called myanimal.

 

Problem description

 

Module works fine when installing (creation of tables, insertion of resources in architecture...).

 

This module has 2 front controllers that work fine too (creating animals).

 

Now I want to add a tab in backoffice so that administrator can see animals created. I plan to use helpers, I just want a basic table list as we have plenty in PS.

 

So I created an AdminAnimalController extending ModuleAdminController and set it in modules/myanimal/controllers/admin/AdminAnimalController.php

 

When installing the module I create the new tab in backoffice right menu, under 'customers'.

 

But when clicking on it I get 'Class 'AdminAnimalController' not found in BASE_DIR/classes/controller/Controller.php on line 134

 

I checked Controller.php ; it is logically about getController method and in my case the controller is not found.

 

What I tried :

 

Delete index_cache in BASE_DIR/cache

Scrutinize database see if I had to save my controller in a routing table...

I thought it could very well be a naming convention problem but when I look at other AdminControllers like AdminCarriersController it seems I am going fine...??

 

But ??? Quid ?

 

Can someone help please ?

 

See below my AdminController file.

 

Alexandre

<?php

class AdminAnimalControllerCore extends ModuleAdminController
{
    public function __construct()
    {
        // INCLUDE NEW OBJECT MODEL FROM MODULE DIRECTORY
        include_once(__DIR__.'../../../classes/MyAnimal.php');

        $this->table = 'my_animal';
        $this->className = 'MyAnimal';
        $this->lang = false;
        $this->deleted = false;
        $this->colorOnBackground = false;
        $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?')));
        $this->context = Context::getContext();
        // définition de l'upload, chemin par défaut _PS_IMG_DIR_
        $this->fieldImageSettings = array('name' => 'image', 'dir' => 'example');
  
        // This adds a multiple deletion button
        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'confirm' => $this->l('Delete selected items?')
            )
        );
  
        parent::__construct();
    }
  
    // This method generates the list of results
    public function renderList()
    {
        // Adds a Delete button for each result
        $this->addRowAction('delete');

        $this->bulk_actions = array(
            'delete' => array(
                'text' => $this->l('Delete selected'),
                'confirm' => $this->l('Delete selected items?')
            )
        );

        // Building the list of records stored within the "test" table
        $this->fields_list = array(
            'id' => array(
                'title' => $this->l('ID'),
                'align' => 'center',
                'width' => 20
            ),
            'id_customer' => array(
                'title' => $this->l('CLIENT'),
                'align' => 'left',
                'width' => 25
            ),
            'name' => array(
                'title' => $this->l('Name'),
                'align' => 'left',
                'width' => 'auto'
            ),
            'date_birth' => array(
                'title' => $this->l('Date de naissance'),
                'align' => 'left',
                'width' => 20
            ),
            'type' => array(
                'title' => $this->l('Espèce'),
                'align' => 'left',
                'width' => 10
            ),
            'age_slice' => array(
                'title' => $this->l('Tranche d\'âge'),
                'align' => 'left',
                'width' => 20
            ),
            'description' => array(
                'title' => $this->l('Description'),
                'align' => 'left',
                'width' => 150
            ),
            'img_url' => array(
                'title' => $this->l('Image'),
                'align' => 'left',
                'width' => 'auto'
            )
        );

        $lists = parent::renderList();
        parent::initToolbar();
        return $lists;
    }
  
    // This method generates the Add/Edit form
    public function renderForm()
    {
        return parent::renderForm();
    }
}

Share this post


Link to post
Share on other sites

Yes of course.

 

Heredown below is my module main file.

 

Just a remark ; I tried in a template to display URL of my adminController with Context::getContext()->link->getAdminLink('AdminAnimal').

 

I notice that url created has a different token than the one attached to the tab. I don't really know if this is relevant for my problem but well it worthes mention it.

 

Ok the code myanimal.php - installTab and uninstallTab

// TAB PANEL FUNCTIONS
    private function installTab($tabClass, $tabName, $idTabParent)
    {
        $tab = new Tab();
        foreach (Language::getLanguages(false) as $language)
            $tab->name[$language['id_lang']] = $tabName;
        $tab->class_name = $tabClass;
        $tab->active = 1;
        $tab->module = $this->name;
        $tab->id_parent = $idTabParent;
        return $tab->save();
    }

    private function uninstallTab($tabClass)
    {
        $idTab = Tab::getIdFromClassName($tabClass);
        if ($idTab != 0) {
            $tab = new Tab($idTab);
            $tab->delete();
            return true;
        }
        return false;
    }

installTab is then called within module's install() method with $this->installTab('AdminAnimal', $this->l('Animaux'), Tab::getIdFromClassName('AdminParentCustomer').

 

Thanks for your help.

 

Alexandre

Share this post


Link to post
Share on other sites

When the dispatcher builds the classname to look for, for an admin controller, it won't add the Core part to the string AdminAnimalControllerCore

// Controllers in modules can be named AdminXXX.php or AdminXXXController.php
include_once(_PS_MODULE_DIR_.$tab->module.'/controllers/admin/'.$controllers[strtolower($this->controller)].'.php');
$controller_class = $controllers[strtolower($this->controller)].(strpos($controllers[strtolower($this->controller)], 'Controller') ? '' : 'Controller');

Share this post


Link to post
Share on other sites

Thanks very very much Roja45 ! You saved me! As I felt it that was a naming problem... I let the 'Core'. So for readers, AdminControllers may be declared in your module directory/controllers/admin/ with class AdminMyNameController extends ModuleAdminController.

 

My mistake was to add the Core at the end of my classname.

 

Thanks again !

Share this post


Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More