Jump to content

Recommended Posts

Greetings,
 
I have a controller called AjaxLayerController.php in MYMODULE/controllers/admin
 
This is how it looks like:
 
class AjaxLayerController extends ModuleAdminController{
        
        public function __construct() {
        
            $this->table         = 'ajax';
            $this->className     = 'Ajax';
        
            parent :: __construct();
        
        }
        
        public function ajaxProcessInvoiceSending() {
            
            return "Ajax working!";
            
        }
    
    }

 

I have tried many things in order to call him. I have tried the values of the following as ajax url:

 

{$link->getModuleLink('AdminOrderUtilities', 'AjaxLayerController')}

{$link->getAdminLink('AjaxLayerController')}

 

And so on.

 

I got this message: Controller not found.

 

If I use the path as url, which in my understanding makes all the Prestashop MVC useless, I have a 500 error code, without test.

 

I would like to found the orthodox way to do it. I assume that all this hierarchy and naming is in order to have a framework going, i wouldn't like to put the entire path to my controller, etc.

 

Thank you very much in advance.

 

Blessings, Miquel.

 

 

Share this post


Link to post
Share on other sites

Hello everyone !

 

I am glad some had the same problem than me... of course not because I like when developers have problems but simply because I may find then a solution to mine...

 

So basically I have the same problem ; my adminController is not found.

 

My customized module is 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

Hello, I come back following info received from Roja45 on the forum.

 

My problem came from the fact that I declared my class like AdminAnimalControllerCore extends ModuleAdminController. Core must be deleted because the dispatcher takes it out when building available classnames.

 

Thanks Roja45.

 

Alexandre

  • Like 1

Share this post


Link to post
Share on other sites

Mdekker's answer it's just fine, but i had to change a bit of this code:

 

$invisible_tab = new Tab();
$invisible_tab->active = 1;
$invisible_tab->class_name = 'AdminName';
$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()

 

It didn't work for me so i had to change

$invisible_tab->add()

for

$invisible_tab->save()

But it's still what i needed to understand how MVC works in prestashop, thank you mdekker.

 

Blessings, Miquel.

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