[WordPress] 外掛分享: Churro

首頁外掛目錄 › Churro
⚠ 此外掛已下架 — 不再更新維護,建議勿安裝。
10+
安裝啟用
尚無評分
4976 天前
最後更新
問題解決
WordPress 2.8.0+ v0.421 上架:2009-09-01

內容簡介

Churro 是一款外掛,讓開發者可以輕鬆建立頁面和功能,類似於 CodeIgniter 的風格。但是單獨使用 Churro 不會在您的 WordPress 網站中新增任何功能。

已測試與 WordPress 及 WordPress MU 2.8.0 ~ 3.0.5。
需要 PHP 5,PHP 4 舊到已經是10年前的事了,您知道嗎?

Churro 基礎

= 網址 =
Churro 需要可讀性較高的網址,而非查詢字串。通常您的網址會製作成以下的映射:yoursite.com/class/method/variables

控制器

控制器會直接映射到相同名稱的檔案和類別。例如:
yoursite.com/contact
會尋找 /churro/ 目錄中名稱為 contact.php 的檔案,該檔案必須有一個延伸 Churro 類別且名稱為 contact 的類別。如果沒有定義的方法,將預設為 index。所有可以透過網址存取的方法都會附加 ‘Action’。以下程式碼提供 scaffolding 以供 yoursite.com/contact 和 yoursite.com/contact/submit 的使用:

<?php
class contact extends Churro {
public function indexAction(){

}

public function submitAction(){

}
}

模型

Churro 讓您可以透過 $this 關鍵字存取幾個重要的 WordPress 模型。不使用 global 關鍵字即可使用 $wp、$wpdb 和 $wp_query 類別,以及 MU 中的 $blog_id。

視圖

視圖屬於正常的佈景主題目錄。如果您使用多個佈景主題,您可以在控制器中使用 $this->Theme( 'directory-name' ) 覆寫目錄。要指定要使用的視圖,使用 $this->View( 'file-name' )。在 Churro 中,將邏輯與視圖分離是最重要的事情。要在您的視圖中設置變數,可以在控制器中使用 $this->vars->var_name,在您的視圖中使用 $var_name。

Ajax / Javascript

如果您使用優秀的 jQuery Javascript 函式庫,Churro 將會偵測到 Ajax 請求並自動返回JSON。Churro 在每個請求中定義了常數 ISAJAX。稍加規劃,就可以非常容易地創建動態應用程式,而這種方式完全可以在沒有使用 Javascript 的情況下進行。

學習 Churro

Churro 中有比本篇更多的功能。截至 2009 年 9 月 2 日,並沒有完整的正式文件可以用來編寫 Churro 代碼。請關注 Substance Labs 教學。

外掛標籤

開發者團隊

⬇ 下載最新版 (v0.421) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「Churro」→ 直接安裝(推薦)

原文外掛簡介

Churro is a plugin that allows developers to easily create pages and functionality, in a style similar to CodeIgniter. By itself, Churro will not add any functionality to your WordPress site.
Tested with WordPress and WordPress MU 2.8.0 ~ 3.0.5
Requires PHP 5. PHP 4 is like 10 years old, you know?
Churro Basics
= URLs =
Churro requires friendly urls rather than query strings. Your url will usually be mapped as following: yoursite.com/class/method/variables
Controllers
The controller will be directly mapped to a file and class with the same name. For example,
yoursite.com/contact
will look for a file named contact.php in the /churro/ directory. This file should have a class contact that extends Churro. Without a defined method, it will default to index. All methods accessible through URLs will have ‘Action’ appended to it. The following code will provide scaffolding for yoursite.com/contact and yoursite.com/contact/submit
wpdb.
Views
Your views belong in your normal theme directory. If you are using multiple themes, you can override the direcotry using $this->Theme( 'directory-name' ) any place in the controller. To specify a view to use, $this->View( 'file-name' ). Seperating logic from views is the most important thing to remember in Churro. To set varaibles in your view, use $this->vars->var_name in the controller, and $var_name in your view.
Ajax / Javascript
If you use the excellent jQuery javascript library, Churro will detect ajax requests and automatically return JSON. Churro defines a constant ISAJAX on each request. With a little planning, it is very easy to create a dynamic application in a way that is totally accessible without javascript.
Learning Churro
There is much more functionality in Churro than outlined here. As of September 2, 2009, there is no complete, formal, documentation for writing code with Churro. Stay tuned to Substance Labs for tutorials.

延伸相關外掛

文章
Filter
Apply Filters
Mastodon