Development Best Practices

From Joomla! Documentation

Revision as of 18:23, 27 May 2013 by Tom Hutchison (talk | contribs) (split template, article is unclear and information may be found elsewhere)
Copyedit.png
This Article Needs Your Help

This article is tagged because it NEEDS IMPROVEMENT. You can help the Joomla! Documentation Wiki by contributing to it.
More pages that need help similar to this one are here. NOTE-If you feel the need is satistified, please remove this notice.



General Development Guidelines[edit]

  • Don't use the DS or DIRECTORY_SEPARATOR constant when including files. It is no longer needed, as pointed out by Christian on php.net
  • Don't depend on register_globals. This is a HIGH security risk, and the feature has been deprecated in PHP 5.3 and removed in 5.4.

Where should I place JavaScript files that belong to my Component?[edit]

Information in response to the question: In com_media, we have an asset folder contains js files; however, is it the proper place for the javascript files for future component development?

The idea was that the asset folder would hold any component asset that would need to be reachable directly by the client. For example, css, img, javascript etc. Initially this was just done to separate them.

Later on in the development of 1.5 we create a general media folder to all assets. At the moment this folder only holds the none-BC system assets. The idea was that the installer would push component specific assets in this folder during the installation process.

In JInstaller around line 780 we see the following in the parseMedia() method:

/*
 * Here we set the folder we are going to copy the files to.
 *     Default 'media' Files are copied to the JPATH_BASE/images folder
 */
$folder = ($element->attributes('destination')) ? $element->attributes('destination') : null;
$destination = JPath::clean(JPATH_ROOT . "/media/{$folder}");

What this means in real terms is that when in your xml install manifest, if you put files insite a <media> tag instead of a <files> tag then they will be sent to the JPATH_ROOT/media folder. If you give it <media destination="com_foo"> then it will put the files in JPATH_ROOT/media/com_foo

In some cases you have a component, we'll say com_foo, and then you have a few modules that go along with com_foo... for sake of the example we'll call them mod_foo_1, mod_foo_2 and mod_foo_3. There is no reason to package media elements for the three modules if they are all the same and they depend upon the component anyway. The best and most logical way to do things is to put them all in a central place that is namespaced appropriately.

Doing it this way gives us the ability to start taking all of the media assets out of our code folders and get us to a point where we could really move all the PHP files underneath the document root. It is a first step toward that end.

For the original discussion, see Joomla! Developer Discussion List.