(Yaf >=1.0.0)
はじめに
Yaf_Controller_Abstract は Yaf システムの中心となるクラスです。 MVC は Model-View-Controller の略で、 アプリケーションのロジックと表示のロジックを切り離すためのデザインパターンです。
すべてのカスタムコントローラは Yaf_Controller_Abstract を継承する必要があります。
カスタムコントローラでは __construct を定義できません。そのため、 Yaf_Controller_Abstract ではマジックメソッド Yaf_Controller_Abstract::init() を用意しています。
カスタムコントローラで init() メソッドを定義すると、 コントローラのインスタンスを作成するときにそれが呼ばれます。
アクションには引数を持たせることができます。 リクエストが来たときに、もしリクエストのパラメータ (Yaf_Request_Abstract::getParam() を参照ください) に同名の変数があれば、Yaf はアクションのメソッド (Yaf_Action_Abstract::execute() を参照ください) にそれを渡します。
注意:
これらの引数は何もフィルタリングせずそのまま取り込まれるので、 実際に使う前には注意しないといけません。
クラス概要
abstract Yaf_Controller_Abstract {
public
$actions
protected
$_module
protected
$_name
protected
$_request
protected
$_response
protected
$_invoke_args
protected
$_view
/* メソッド */
final private __construct ( )
protected display
( string $tpl
[, array $parameters
] ) : bool
public forward
( string $action
[, array $paramters
] ) : void
public getInvokeArg
( string $name
) : void
public getInvokeArgs ( ) : void
public getModuleName ( ) : string
public getName ( ) : string
public getRequest ( ) : Yaf_Request_Abstract
public getResponse ( ) : Yaf_Response_Abstract
public getView ( ) : Yaf_View_Interface
public getViewpath ( ) : string
public init ( ) : void
public initView
([ array $options
] ) : void
public redirect
( string $url
) : bool
protected render
( string $tpl
[, array $parameters
] ) : string
public setViewpath
( string $view_directory
) : void
}
プロパティ
actions
アクションメソッドを個別の PHP スクリプトとして定義することもできます。 そのときには、このプロパティと Yaf_Action_Abstract を利用します。
例1 別ファイルでのアクションの定義
<?phpclass IndexController extends Yaf_Controller_Abstract { protected $actions = array( /** now dummyAction is defined in a separate file */ "dummy" => "actions/Dummy_action.php", ); /* action method may have arguments */ public indexAction($name, $id) { /* $name and $id are unsafe raw data */ assert($name == $this->getRequest()->getParam("name")); assert($id == $this->_request->getParam("id")); }}?>
例2 Dummy_action.php
<?phpclass DummyAction extends Yaf_Action_Abstract { /* a action class shall define this method as the entry point */ public execute() { }}?>
_module
モジュール名
_name
コントローラ名
_request
現在のリクエストオブジェクト
_response
現在のレスポンスオブジェクト
_invoke_args
_view
ビューエンジンオブジェクト
目次
- Yaf_Controller_Abstract::__construct — Yaf_Controller_Abstract のコンストラクタ
- Yaf_Controller_Abstract::display — The display purpose
- Yaf_Controller_Abstract::forward — 別のアクションに転送する
- Yaf_Controller_Abstract::getInvokeArg — The getInvokeArg purpose
- Yaf_Controller_Abstract::getInvokeArgs — The getInvokeArgs purpose
- Yaf_Controller_Abstract::getModuleName — モジュール名を取得する
- Yaf_Controller_Abstract::getName — Get self name
- Yaf_Controller_Abstract::getRequest — 現在のリクエストオブジェクトを取得する
- Yaf_Controller_Abstract::getResponse — 現在のレスポンスオブジェクトを取得する
- Yaf_Controller_Abstract::getView — ビューエンジンを取得する
- Yaf_Controller_Abstract::getViewpath — getViewpath の目的を書く
- Yaf_Controller_Abstract::init — コントローラを初期化する
- Yaf_Controller_Abstract::initView — The initView purpose
- Yaf_Controller_Abstract::redirect — URL にリダイレクトする
- Yaf_Controller_Abstract::render — ビューテンプレートをレンダリングする
- Yaf_Controller_Abstract::setViewpath — The setViewpath purpose
/* プロパティ */