J3.x

Difference between revisions of "Developing an MVC Component/Introduction/zh-tw"

From Joomla! Documentation

< J3.x:Developing an MVC Component
(Created page with "開發一個 MVC 元件")
 
(Created page with "S:MyLanguage/J3.x:Developing_an_MVC_Component/Developing_a_Basic_Component|下一篇:開發一個基礎元件")
 
(15 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
<noinclude><languages /></noinclude>
 
<noinclude><languages /></noinclude>
{{:J3.1:Developing an MVC Component/en}}
+
{{:J3.1:Developing an MVC Component/zh-tw}}
==Notes==
+
==注意==
* If you are new to Joomla!, please read [[S:MyLanguage/Absolute_Basics_of_How_a_Component_Functions|Absolute Basics of How a Component Functions]].  
+
* 假如您初來乍到 Joomla!,請先閱讀[[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]]
+
* 這一個教學是從 [[User:Cdemko|Christophe Demko]]: [[S:MyLanguage/Developing a Model-View-Controller Component/2.5|Developing a Model-View-Controller Component/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]]
+
**'''警告:''' 這一篇教學沒有重複 Demko 原始文章中的內容,要查看它們,請到 Joomla! 2.5 原始的教學內容:[[S:MyLanguage/Developing_a_Model-View-Controller_Component/2.5/Introduction|Developing an MVC Component for Joomla! 2.5 - Introduction]]
  
== Requirements ==
+
== 需求 ==
You need Joomla! 3.0 (with PHP, MySQL and Apache/Microsoft IIS) or greater for this tutorial.
+
您需要 Joomla! 3.0 (PHP, MySQL 以及 Apache/Microsoft IIS) 或更高版本,來符合本教學。
I gathered a lot of information and then I started to migrate the component of the new Joomla! 2.5 to 3.0.
+
我收集了很多資訊,接著開始將元件從2.5移轉為3.0。
Below is some important information used for migration. Please see also all the information about migration [[S:MyLanguage/Portal:Upgrading_Versions|Upgrading Versions]].
+
以下是一些和移轉元件有關的重要資訊,也請閱讀其他所有的 [[S:MyLanguage/Portal:Upgrading_Versions|升級版本]]文章。
Use "display_errors On" to help with debugging errors.
+
使用 "display_errors On" 來協助除錯。
  
== Migrating Joomla! 2.5 to Joomla! 3.0: ==
+
== Joomla! 2.5 移轉到 Joomla! 3.0: ==
 
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.
 
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.
 
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.
Line 18: Line 18:
 
(Elin in development list)
 
(Elin in development list)
  
Samples:
+
範例:
 
DS
 
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.  
 
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.  
Line 53: Line 53:
 
</source>
 
</source>
  
Here source code:
+
這裡是原始碼:
 
http://joomlacode.org/gf/project/hellojoomla3/frs/
 
http://joomlacode.org/gf/project/hellojoomla3/frs/
  
== New MVC in Joomla! 3.0 ==
+
==Joomla! 3.0 新的 MVC ==
 
"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]
 
[http://developer.joomla.org/manual/chap-Joomla_Platform_Manual-MVC.html Joomla! Platform Manual MVC]
  
== Contributors ==
+
== 貢獻 ==
 
* [[User:Ribafs|Ribafs]]
 
* [[User:Ribafs|Ribafs]]
 
* [[User:Kevinkabatra | Kevin Kabatra]]
 
* [[User:Kevinkabatra | Kevin Kabatra]]
  
 
<div class="row">  
 
<div class="row">  
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Introduction|Prev: Introduction|class=expand success}}</div>
+
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Introduction|上一篇:我們從簡介開始|class=expand success}}</div>
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Developing_a_Basic_Component|Next: Developing a Basic Component|class=expand}}</div>
+
<div class="large-6 columns">{{Basic button|S:MyLanguage/J3.x:Developing_an_MVC_Component/Developing_a_Basic_Component|下一篇:開發一個基礎元件|class=expand}}</div>
 
</div>
 
</div>
 
__NOTOC__
 
__NOTOC__

Latest revision as of 02:45, 4 January 2021

Other languages:
العربية • ‎Deutsch • ‎English • ‎español • ‎français • ‎Nederlands • ‎português do Brasil • ‎中文(中国大陆)‎ • ‎中文(台灣)‎
Joomla! 
3.x
教學
開發一個 Model-View-Controller 元件


這是一系列的多篇文章,旨在介紹如何開發一個 Joomla! VersionJoomla 3.x Model-View-Controller 元件

讓我們從簡介開始,您可以使用底下的導覽按鈕來瀏覽文章,或是右側的方塊中的連結(列出所有的文章)。



注意

需求

您需要 Joomla! 3.0 (PHP, MySQL 以及 Apache/Microsoft IIS) 或更高版本,來符合本教學。 我收集了很多資訊,接著開始將元件從2.5移轉為3.0。 以下是一些和移轉元件有關的重要資訊,也請閱讀其他所有的 升級版本文章。 使用 "display_errors On" 來協助除錯。

從 Joomla! 2.5 移轉到 Joomla! 3.0:

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)

範例: 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;

這裡是原始碼: http://joomlacode.org/gf/project/hellojoomla3/frs/

Joomla! 3.0 新的 MVC

"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

貢獻