Reputation: 5181
I am developing a PrestaShop module, which will have it's own database tables. Let's say database table name is 'cat'. So I wanted to have a model class named Cat to keep track of it's properties and related operations. So where should it?
For example, there are prestashop core model classes inside classes directory. Is it ok to create a classes directory inside my module directory for that purpose? will it work?
Upvotes: 0
Views: 6273
Reputation: 367
The standard used is to place the model class in /module/model/YourModelClass.php, you can see this module and in your installation module class you should call it
require_once(_PS_MODULE_DIR_ . 'example/models/YourModelClass.php');
you have not a strict naming standard to your class model, like it does it the controller class and installation class.
Hope that it helps.
Cordially.
Upvotes: 3
Reputation: 5181
My question was about where to place ObjectModel subclasses in prestashop. Above accepted answer is answering that question. But that's not enough to work the module correctly. You will have to include your model class where ever you want to use inside the module.
for example
include_once(_PS_MODULE_DIR_.'mymodule/classes/Cat.php');
class mymoduledisplayModuleFrontController extends ModuleFrontController {
// Other code goes here
}
If you are overriding existing model class, you can put your class inside /modules/your_module/override/classes directory. I have noticed while installing module, your overridden classes will be copied to the prestashop_root/override/classes directory.
Upvotes: 1
Reputation: 16107
PrestaShop model structure is pretty free-flowing. You can decide what structure you want to use.
The only few constraints imposed on you are
Upvotes: 1