Jump to content

Questions on the official dev. guide


babthooka

Recommended Posts

Theres a tutorial-like document on the original dev. guide on how to make modules and their tabs on the back office.

 

On it, it is explained that one must create a "MyModule.php" document on the classes/ directory, containing a class definition for your module, like so:

 

<?php
class Test extends ObjectModel
 {
 /** @var string Name */
 public $test;

 protected $fieldsRequired = array('test');
 protected $fieldsSize = array('test' => 64);
 protected $fieldsValidate = array('test' => 'isGenericName');
 protected $table = 'test';
 protected $identifier = 'id_test';

 public function getFields()
{
parent::validateFields();
$fields['test'] = pSQL($this->test);
return $fields;
}
 }
?>

 

I've been pondering on this for a while, and have come to the conclusion that I don't get it (no surprise there).

 

Can anyone tell me what this is actually for? I have been looking at every other module included by default on Prestashop, and couldn't find even one single module that had a corresponding class file in the classes folder. It seems modules can perfectly exist without this file there (and none of the other tutorials I found use this for anything), so why does the official Prestashop documentation put it there?

 

Thanks

Link to comment
Share on other sites

Hi.

 

The rule for creating modules, is that the folder, the module file and the class name must be the same.

 

So if the file name is MyModule.php, than the class name is also MyModule and the folder is also mymodule. Also the module classes extend the Module class and not the ObjectModel.

 

The code you put in there is not for creating a new module.

 

Regards.

 

Robin.

 

The CartExpert Team

Link to comment
Share on other sites

Hi,

 

I think document might not be clear about this.

It's not mandatory to create an object model.

 

If you want to create an AdminTab just to display some informations, you do not need to create an object model.

For example, if you want an AdminTab for feed rss, it can be interesting to create an ObjectModel RssFeed, you will be able to use AdminTab methods, such as displayList or displayForm.

 

Look at this two tabs AdminManufacturers.php and AdminTranslations.php, in AdminManufacturers.php, there is these lines :

$this->className = 'Manufacturer';

It means it will use the Manufacturer ObjectModel.

 

In AdminTranslations, there is no such line because ObjectModel is not necessary in this case :)

 

Do not hesitate to tell me if it's not clear :)

Link to comment
Share on other sites

Hello!

 

Thank you for your answers first of all.

 

Referring to your RSS example Fabien, if I make an AdminRSSTab for such a module, it will have to inherit from the main AdminTab according to the official docs, correct? As follows:

 

<?php
include_once(PS_ADMIN_DIR.'/../classes/AdminTab.php');
class AdminRSSTab extends AdminTab {
...
...
...
}

 

Or something like that. Since it inherits from AdminTab, will this not give access to AdminTab methods as it is, without having to create a class file in the classes directory?

 

Inspecting further on the files you suggest I look at, I can see that all(?) class files inherit from ObjectModel, which, to me, suggests access to a whole other set of inherited methods (not the ones in AdminTab - these are already accessible anyhow). Am I not correct in this?

 

 

So in total, I am afraid I still don't know what the purpose of these class files in the classes directory is. :wacko:

Link to comment
Share on other sites

Also, it seems to me that these class files are there to somehow extend or support the tab files, and not the modules, as I first thought (which is why I was trying to correspond modules to class files without any success). Am I also correct (or wrong) in this?

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