8

When developing a Joomla extension, are there any best practices, guidelines or recommendations regarding where to place the different parts of my code (PHP and HTML)?

I'm mostly thinking about the basic files included in a module:

mod_mymodule.php
helper.php
tmpl/default.php

Additionally, what are the main benefits of including a helper.php file, and can it be removed in some cases?

1

2 Answers 2

7

helper.php:

This file is where all your functions belonging to a class should go. It's basically the module version of a model for a component, so tasks such as performing database queries etc. The benefits of this file is that it keeps all the core functionality in 1 location. If a module already contains this file, 1 simple rule, do not remove it.

mod_mymodule.php:

As @subashbasnet8 has already mentioned, this file is where you can call your functions and also a good place to get the module parameters and define them as a variable. You should also do things such as get your POST variables in here. HTML markup should not belong in this file.

default.php:

This file should contain all your HTML markup simply due to the fact that it will then allow the user (or even yourserlf) to override it, which is something you cannot do with the other 2 files. Also things like importing CSS/JS libraries should go in here too, again, so that any overrides can be performed.

5

Basically, mod_mymodule.php is a bootstrap page of your module. Here you will include helper file and call necessary function which resides in helper.php. you can put HTML code in tmpl/default.php page and php code in helper and mod_mymodule.php page.

For more detail please see this. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.