Skip to content

進階 MVC Class 使用範例

Leo edited this page Feb 21, 2014 · 13 revisions

進階 MVC Class 使用範例

我們可以使用 Joomla! 內建的 Controller Class 與 Model Class 來快速地完成 table 的 CRUD

會使用到的 Class 清單如下:

本範例的主題為 「建立 Blog 文章後台」

開發順序

  1. 建立 Blog Component
  2. 建立 #__blog_items table
  3. 建立 Item JTable
    建立出來的 BlogTableItem 會被用在 BlogModelItem
  4. 建立 Items model
  5. 建立 Items view
  6. 建立 Item controller
  7. 建立 Item form
  8. 建立 Item model
    必須實作 getForm 的函式
  9. 建立 Item view
  10. 建立 Item view toolbar
  11. 修正不能儲存 HTML content 的問題
  12. 建立 Items controller
  13. 修改 Items view toolbar
  14. 建立 Items view 分頁
  15. 建立 Items view 排序
    • 排序處理需要修改 Items model 內的建構子,使用 $config['filter_fields'] 參數來設定需要排序的欄位清單
    • 在 Items view 的 template 中使用 JHtml::_('grid.sort') 的 Helper 顯示可以排序的欄位
    • 以下是會使用到的 Joomla! model state keywords
      • list.ordering 排序欄位,對應到 input 的 filter_order 欄位
      • list.direction 昇冪(ASC)或是降冪(DESC)排序,對應到 input 的 filter_order_Dir 欄位
  16. 建立 Items view 篩選條件
Clone this wiki locally