J3.x

Difference between revisions of "Developing an MVC Component/Introduction"

From Joomla! Documentation

< J3.x:Developing an MVC Component
(Undo revision 202936 by MarkRS (talk))
m (added recommend way of declaring system paths)
 
(10 intermediate revisions by 4 users not shown)
Line 2: Line 2:
 
{{:J3.1:Developing an MVC Component/<translate><!--T:1-->
 
{{:J3.1:Developing an MVC Component/<translate><!--T:1-->
 
en</translate>}}
 
en</translate>}}
<translate>==Notes== <!--T:2-->
+
<translate>
This tutorial is adapted from [[User:Cdemko|Christophe Demko]]:  
+
==Notes== <!--T:27-->
*[[S:MyLanguage/Developing a Model-View-Controller Component/2.5|Developing a Model-View-Controller Component/2.5]]</translate>
+
</translate>
 +
<translate><!--T:28-->
 +
* If you are new to Joomla!, please read [[S:MyLanguage/Absolute_Basics_of_How_a_Component_Functions|Absolute Basics of How a Component Functions]].
 +
* This tutorial is adapted from [[User:Cdemko|Christophe Demko]]: [[S:MyLanguage/Developing a Model-View-Controller Component/2.5|Developing a Model-View-Controller Component/2.5]]</translate>
 
<translate><!--T:3-->
 
<translate><!--T:3-->
'''WARNING:''' this tutorial will not repeat the comments of Demko. To see them, please have a look at the original tutorial for Joomla! 2.5:
+
**'''WARNING:''' this tutorial will not repeat the comments of Demko. To see them, please have a look to the original tutorial for Joomla! 2.5:[[S:MyLanguage/Developing_a_Model-View-Controller_Component/2.5/Introduction|Developing an MVC Component for Joomla! 2.5 - Introduction]]</translate>
*[[S:MyLanguage/Developing_a_Model-View-Controller_Component/2.5/Introduction|Developing a MVC Component for Joomla! 2.5 - Introduction]]</translate>
+
 
<translate>== Requirements == <!--T:7--></translate>
+
<translate>
 +
== Requirements == <!--T:7-->
 +
</translate>
 
<translate><!--T:8-->
 
<translate><!--T:8-->
 
You need Joomla! 3.0 (with PHP, MySQL and Apache/Microsoft IIS) or greater for this tutorial.</translate>
 
You need Joomla! 3.0 (with PHP, MySQL and Apache/Microsoft IIS) or greater for this tutorial.</translate>
Line 17: Line 22:
 
Use "display_errors On" to help with debugging errors.</translate>
 
Use "display_errors On" to help with debugging errors.</translate>
  
<translate>== Migrating Joomla! 2.5 to Joomla! 3.0: == <!--T:11--></translate>
+
<translate>
 +
== Migrating Joomla! 2.5 to Joomla! 3.0: == <!--T:11-->
 +
</translate>
 
<translate><!--T:12-->
 
<translate><!--T:12-->
 
Remember that you need to add Legacy at any place where you are directly extending JModel, JView or JController.  If it is indirect (like through JModelList) you don't have to, it's already taken care of.</translate>
 
Remember that you need to add Legacy at any place where you are directly extending JModel, JView or JController.  If it is indirect (like through JModelList) you don't have to, it's already taken care of.</translate>
Line 30: Line 37:
 
DS
 
DS
 
<translate><!--T:16-->
 
<translate><!--T:16-->
Since we've removed the DS constant in 3.0, we need to replace the uses of the constant in com_media.  The most unobtrusive change is to simply replace it with PHP's DIRECTORY_SEPARATOR constant since DS is an alias to that.</translate>
+
Since we've removed the DS constant in 3.0, we need to replace the uses of the constant in com_media.  The most unobtrusive change is to simply replace it with PHP's DIRECTORY_SEPARATOR constant since DS is an alias to that. However, the recommended way to do it is to simply use the slash, i.e. 'components/com_example/models/example.php' instead of 'components'.DS.'com_example'.DS.'models'.DS.'example.php'. This is windows safe. </translate>
  
 
(joomlacode)
 
(joomlacode)
Line 67: Line 74:
 
http://joomlacode.org/gf/project/hellojoomla3/frs/
 
http://joomlacode.org/gf/project/hellojoomla3/frs/
  
<translate>== New MVC in Joomla! 3.0 == <!--T:18--></translate>
+
<translate>
 +
== New MVC in Joomla! 3.0 == <!--T:18-->
 +
</translate>
 
<translate><!--T:19-->
 
<translate><!--T:19-->
 
"Version 12.1 of the platform introduced a new format for the model-view-controller paradigm. In principle, the classes JModel, JView and JController are now interfaces and the base abstract classes are now JModelBase, JViewBase and JControllerBase, respectively. In addition, all classes have been simplified, removing a lot of coupling with the Joomla! CMS, that was unnecessary for standalone Joomla! Platform applications." ...
 
"Version 12.1 of the platform introduced a new format for the model-view-controller paradigm. In principle, the classes JModel, JView and JController are now interfaces and the base abstract classes are now JModelBase, JViewBase and JControllerBase, respectively. In addition, all classes have been simplified, removing a lot of coupling with the Joomla! CMS, that was unnecessary for standalone Joomla! Platform applications." ...
 
[http://developer.joomla.org/manual/chap-Joomla_Platform_Manual-MVC.html Joomla! Platform Manual MVC]</translate>
 
[http://developer.joomla.org/manual/chap-Joomla_Platform_Manual-MVC.html Joomla! Platform Manual MVC]</translate>
  
<translate>== Contributors == <!--T:22--></translate>
+
<translate>
 +
== Contributors == <!--T:22-->
 +
</translate>
 
* [[User:Ribafs|Ribafs]]
 
* [[User:Ribafs|Ribafs]]
 +
* [[User:Kevinkabatra | Kevin Kabatra]]
  
 
<div class="row">  
 
<div class="row">  
 
<div class="large-6 columns">{{Basic button|<translate>
 
<div class="large-6 columns">{{Basic button|<translate>
 
<!--T:24-->
 
<!--T:24-->
S:MyLanguage/J3.x:Developing_a_MVC_Component/Introduction|Prev: Introduction</translate>|class=expand success}}</div>
+
S:MyLanguage/J3.x:Developing_an_MVC_Component/Introduction|Prev: Introduction</translate>|class=expand success}}</div>
 
<div class="large-6 columns">{{Basic button|<translate>
 
<div class="large-6 columns">{{Basic button|<translate>
 
<!--T:25-->
 
<!--T:25-->
S:MyLanguage/J3.x:Developing_a_MVC_Component/Developing_a_Basic_Component|Next: Developing a Basic Component</translate>|class=expand}}</div>
+
S:MyLanguage/J3.x:Developing_an_MVC_Component/Developing_a_Basic_Component|Next: Developing a Basic Component</translate>|class=expand}}</div>
 
</div>
 
</div>
 
+
__NOTOC__
 
<noinclude>
 
<noinclude>
 
<translate>
 
<translate>

Latest revision as of 00:24, 21 October 2016

Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎italiano • ‎português do Brasil • ‎العربية • ‎中文(中国大陆)‎ • ‎中文(台灣)‎
Joomla! 
3.x
Tutorial
Developing an MVC Component


This is a multiple-article series of tutorials on how to develop a Model-View-Controller Component for Joomla! VersionJoomla 3.x.

Begin with the Introduction, and navigate the articles in this series by using the navigation button at the bottom or the box to the right (the Articles in this series).



Notes[edit]

Requirements[edit]

You need Joomla! 3.0 (with PHP, MySQL and Apache/Microsoft IIS) or greater for this tutorial. I gathered a lot of information and then I started to migrate the component of the new Joomla! 2.5 to 3.0. Below is some important information used for migration. Please see also all the information about migration Upgrading Versions. Use "display_errors On" to help with debugging errors.

Migrating Joomla! 2.5 to Joomla! 3.0:[edit]

Remember that you need to add Legacy at any place where you are directly extending JModel, JView or JController. If it is indirect (like through JModelList) you don't have to, it's already taken care of. Other than that and the fact that, as announced long ago, deprecated code has been removed (I'd guess that JParameter is the biggest impact), extensions should only need minor changes ... Although you will want to look at the output changes that Kyle is working on. Of course, if you are building standalone platform applications, the new MVC and JApplicationWeb/JApplicationCLI are completely the way you should work and the nice thing about the way we have done this is that the new packages are already right there on your server having arrived with the CMS. (Elin in development list)

Samples: DS Since we've removed the DS constant in 3.0, we need to replace the uses of the constant in com_media. The most unobtrusive change is to simply replace it with PHP's DIRECTORY_SEPARATOR constant since DS is an alias to that. However, the recommended way to do it is to simply use the slash, i.e. 'components/com_example/models/example.php' instead of 'components'.DS.'com_example'.DS.'models'.DS.'example.php'. This is windows safe.

(joomlacode)

if(!defined('DS')){
define('DS',DIRECTORY_SEPARATOR);
}

//$controller = JController::getInstance('HelloWorld');
$controller = JControllerLegacy::getInstance('HelloWorld');

//class HelloWorldViewHelloWorlds extends JView
class HelloWorldViewHelloWorlds extends JViewLegacy

class HelloWorldController extends JControllerLegacy

class HelloWorldModelHelloWorld extends JModelItemLegacy

class HelloWorldModelUpdHelloWorld extends JModelFormLegacy

JRegistry::getValue() now is JRegistry::get()

//Convert sample to JRegistry with LoadJSON - Sample from Joomla! 3.0 sourcecode

//				$params = new JRegistry;
//				$params->loadJSON($this->item->params);
//				$this->item->params = $params;

				$params = new JRegistry;
				$params->loadString($item->params);
				$item->params = $params;

Here source code: http://joomlacode.org/gf/project/hellojoomla3/frs/

New MVC in Joomla! 3.0[edit]

"Version 12.1 of the platform introduced a new format for the model-view-controller paradigm. In principle, the classes JModel, JView and JController are now interfaces and the base abstract classes are now JModelBase, JViewBase and JControllerBase, respectively. In addition, all classes have been simplified, removing a lot of coupling with the Joomla! CMS, that was unnecessary for standalone Joomla! Platform applications." ... Joomla! Platform Manual MVC

Contributors[edit]