Actions

Difference between revisions of "Development Best Practices"

From Joomla! Documentation

(New page: == Where Should I Place JavaScript files that belong to my Component? == Information in response to the question: In com_media, we have an asset folder contains js files; however, is it ...)
 
m (Minor spelling)
(5 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 
+
== Where should I place JavaScript files that belong to my Component? ==
== Where Should I Place JavaScript files that belong to my Component? ==
+
  
 
Information in response to the question:
 
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 develop?
+
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. Initialy this was just done to seperate them.
+
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
 
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
Line 12: Line 11:
 
In JInstaller around line 780 we see the following in the parseMedia() method:
 
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
+
* 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);
+
$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 23: Line 24:
 
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.
+
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 [http://groups.google.com/group/joomla-devel/browse_thread/thread/49c457b9305e1379 Joomla! Developer Discussion List].
  
[http://groups.google.com/group/joomla-devel/browse_thread/thread/49c457b9305e1379 Joomla! Developer Discussion List]
+
[[Category:Development]]

Revision as of 19:49, 26 June 2011

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

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')) ? DS.$element->attributes('destination') : null;
$destination = JPath::clean(JPATH_ROOT.DS.'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.