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/ | + | {{:J3.1:Developing an MVC Component/zh-tw}} |
− | == | + | ==注意== |
− | * | + | * 假如您初來乍到 Joomla!,請先閱讀[[S:MyLanguage/Absolute_Basics_of_How_a_Component_Functions|Absolute Basics of How a Component Functions]]. |
− | * | + | * 這一個教學是從 [[User:Cdemko|Christophe Demko]]: [[S:MyLanguage/Developing a Model-View-Controller Component/2.5|Developing a Model-View-Controller Component/2.5]] 引用出來的。 |
− | **''' | + | **'''警告:''' 這一篇教學沒有重複 Demko 原始文章中的內容,要查看它們,請到 Joomla! 2.5 原始的教學內容:[[S:MyLanguage/Developing_a_Model-View-Controller_Component/2.5/Introduction|Developing an MVC Component for Joomla! 2.5 - Introduction]] |
− | == | + | == 需求 == |
− | + | 您需要 Joomla! 3.0 (PHP, MySQL 以及 Apache/Microsoft IIS) 或更高版本,來符合本教學。 | |
− | + | 我收集了很多資訊,接著開始將元件從2.5移轉為3.0。 | |
− | + | 以下是一些和移轉元件有關的重要資訊,也請閱讀其他所有的 [[S:MyLanguage/Portal:Upgrading_Versions|升級版本]]文章。 | |
− | + | 使用 "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. | 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) | ||
− | + | 範例: | |
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> | ||
− | + | 這裡是原始碼: | |
http://joomlacode.org/gf/project/hellojoomla3/frs/ | 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." ... | "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] | ||
− | == | + | == 貢獻 == |
* [[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| | + | <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| | + | <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
Articles in this Series
- Introduction
- Developing a Basic Component
- Adding a view to the site part
- Adding a menu type to the site part
- Adding a model to the site part
- Adding a variable request in the menu type
- Using the database
- Basic backend
- Adding language management
- Adding backend actions
- Adding decorations to the backend
- Adding verifications
- Adding categories
- Adding configuration
- Adding ACL
- Adding an install/uninstall/update script file
- Adding a front-end form
- Adding an image
- Adding a map
- Adding AJAX
- Adding an alias
- Using the language filter facility
- Adding a Modal
- Adding Associations
- Adding Checkout
- Adding Ordering
- Adding Levels
- Adding Versioning
- Adding Tags
- Adding Access
- Adding a batch process
- Adding Cache
- Adding a Feed
- Adding an update server
- Adding Custom Fields
這是一系列的多篇文章,旨在介紹如何開發一個 Joomla! Version Model-View-Controller 元件
讓我們從簡介開始,您可以使用底下的導覽按鈕來瀏覽文章,或是右側的方塊中的連結(列出所有的文章)。
注意
- 假如您初來乍到 Joomla!,請先閱讀Absolute Basics of How a Component Functions.
- 這一個教學是從 Christophe Demko: Developing a Model-View-Controller Component/2.5 引用出來的。
- 警告: 這一篇教學沒有重複 Demko 原始文章中的內容,要查看它們,請到 Joomla! 2.5 原始的教學內容:Developing an MVC Component for Joomla! 2.5 - Introduction
需求
您需要 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