So you want to create a new page. It’s really easy, you just need to write a few lines of code.
This tutorial is for PrestaShop 1.6. Other versions are similar but can slightly differ.
Let’s say we want to create a “Test” controller for a module “MyModule“. Change “Test” and “MyModule” to your actual values.
- First you need to navigate to your module’s directory.
- Create there a new directory “controllers“. And inside it create a directory “front“.
So the file structure should be “mymodule/controllers/front/” - In that “front” directory create a new PHP file: test.php
- Paste the following code into that file:
1
2
3class MyModuleTestModuleFrontController extends ModuleFrontController
{
}As you can see, controller’s class extends ModuleFrontController and should be called like <module_name><controller_name>ModuleFrontController.
All done!
You can view your new page by the following url:
your_site/index.php?fc=module&module=mymodule&controller=test
OR
your_site/module/mymodule/test
Go to your Back Office to the tab Preferences > SEO & URLs. There you can click “Add a new page” and set a custom friendly url for your page.
Now, you can customize the new page
For example, use the display_column_left variable to control left column displaying.
1 2 3 4 | class MyModuleTestModuleFrontController extends ModuleFrontController { public $display_column_left = false; } |
Let’s add some content to the new page
Create a new template file: “mymodule/views/templates/front/test.tpl” and place there some text.
Use that template:
1 2 3 4 5 6 7 8 9 | class MyModuleTestModuleFrontController extends ModuleFrontController { public function initContent() { parent::initContent(); $this->setTemplate('test.tpl'); } } |
Very good tutorial.
Thank you very mutch.
I’m using presta 1.7.6 and the same 404 error.
Does anyone know to to solve it?
Cheers
Victor
Same problem, I get a 404 error…
Presta 1.6.1
Hello,
first of all, thanks for the explanation.
I have followed the instructions, but there is a 404 error when I try to open the page …. /index.php?fc=module&module=mymodule&controller=test
cache/class_index.php was deleted
Seo & url >> modul-path: module/{module}{/:controller}
Regards
Tom