Actions

Difference between revisions of "Development Best Practices"

From Joomla! Documentation

(Where should I place JavaScript files that belong to my Component?: Neaten up question to Joomla 1.6+ standards)
(14 intermediate revisions by 7 users not shown)
Line 1: Line 1:
== Where Should I Place JavaScript files that belong to my Component? ==
+
{{page|needs improvement|It is severely outdated and needs a major revision.}}
 +
{{split|Would this be better split into FAQ type page? Otherwise I suggest deletion.}}
  
Information in response to the question:
+
== General Development Guidelines ==
In com_media, we have an asset folder contains js files; however, is it the proper place for the javascript files for future component develop?
+
  
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. Initialy this was just done to seperate them.
+
* Don't use the DS or DIRECTORY_SEPARATOR constant when including files. It is no longer needed, as pointed out by [http://us2.php.net/manual/en/ref.filesystem.php#73954 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.
  
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
+
== Where should I place JavaScript, CSS files that belong to my Component? ==
assets.  The idea was that the installer would push component specific assets in this folder during the installation process.
+
You can see in your root a general media folder to hold all assets.
 
+
In JInstaller around line 780 we see the following in the parseMedia() method:
+
 
+
<source lang="php">
+
/*
+
* 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')) ? DS.$element->attributes('destination') : null;
+
$destination = JPath::clean(JPATH_ROOT.DS.'media'.$folder);
+
</source>
+
  
 
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
 
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
Line 24: Line 14:
 
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.  
 
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 sto a point where we could really move all the PHP files underneath the document root.  It is a first step toward that end.
+
[[Category:Development]]
 
+
[[Category:JavaScript]]
[http://groups.google.com/group/joomla-devel/browse_thread/thread/49c457b9305e1379 Joomla! Developer Discussion List]
+

Revision as of 08:31, 29 October 2013

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.

Reason: It is severely outdated and needs a major revision.



General Development Guidelines

  • 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, CSS files that belong to my Component?

You can see in your root a general media folder to hold all assets.

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.