J3.x

開發一個 MVC 元件

From Joomla! Documentation

< J3.x:Developing an MVC Component
This page is a translated version of the page J3.x:Developing an MVC Component/Introduction and the translation is 95% complete.
Other languages:
Deutsch • ‎English • ‎Nederlands • ‎español • ‎français • ‎italiano • ‎polski • ‎português do Brasil • ‎العربية • ‎中文(中国大陆)‎ • ‎中文(台灣)‎
Joomla! 
3.x
教學
開發一個 Model-View-Controller 元件

在選單類型中新增一個變數請求

使用資料庫

基本的後台

新增語言管理

新增後台行為

新增後台的佈置

新增表單驗證

新增類別

新增設定介面

  1. 新增 ACL

新增一個安裝/移除/更新程式碼檔案

新增一個前台表單

  1. 新增一個圖片
  2. 新增一個 map
  3. 新增 AJAX
  4. 新增一個別名

使用語言過濾功能

  1. 新增一個 model
  2. 新增關聯
  3. 新增回存
  4. 新增排序
  5. 新增階層
  6. 新增版本控制
  7. 新增標籤
  8. 新增存取權限
  9. 新增批次作業
  10. 新增快取
  11. 新增 Feed

新增更新伺服器

  1. 新增客製化欄位
  2. Upgrading to Joomla4



這是一系列的多篇文章,旨在介紹如何開發一個 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:

請記得您需要在每一個您想要直接擴展 JModel , JView 或是 JController 的地方新增 legacy 。如果非直接 (例如透過 JModelList) 則您不需要這樣做,程式本身已經有準備好了。 另外一項影響是,我們講了很久的,過時程式碼被移除了 (我猜 JParameter 會是最大的衝擊所在),擴充套件應該只需要些微修改 ... 雖然您會想要看修改之後的樣子, Kyle 正在做這一部分。 當然,假如您正在建立獨立運作的應用程序,新的 MVC 以及JApplicationWeb/JApplicationCLI 絕對是您需要使用的。關於我們所完成的新程式包已經伴隨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 平台導入了新的 model-view-controller 範例格式。原則上,名為 JModel , JView JController 的class 現在是介面(interface),其基本 abstract classes 改為 JModelBase , J ViewBase JControllerBase 。此外,所有的 class 都被簡化,移掉了很多與Joomla CMS相耦合的內容,因為那對於獨立運作的 Joomla! Platform 應用程序來說並不需要" ... Joomla! Platform Manual MVC

貢獻者