Php/docs/class.yaf-controller-abstract

提供:Dev Guides
< Php
移動先:案内検索

(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 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

ビューエンジンオブジェクト


目次