文字

The Yaf_Controller_Abstract class

(Yaf >=1.0.0)

简介

Yaf_Controller_Abstract 是Yaf的MVC体系的核心部分。 MVC是指Model-View-Controller, 是一个用于分离应用逻辑和表现逻辑的设计模式。

每个用户自定义controller都应当继承Yaf_Controller_Abstract

你会发现在你自己的controller中无法定义__construct方法。因此,Yaf_Controller_Abstract 提供了一个魔术方法Yaf_Controller_Abstract::init()。

如果在你自己的controller里面已经定义了一个init()方法,当你的controller被实例化的时候,它将被调用。

Action可能需要参数,当一个请求来到的时候,在路由中如果请求的参数有相同名称的变量(例如: Yaf_Request_Abstract::getParam() ), Yaf将把他们传递给action方法(see 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 void __clone ( void )
final private __construct ( void )
protected bool display ( string $tpl [, array $parameters ] )
public void forward ( string $module [, string $controller [, string $action [, array $paramters ]]] )
public void getInvokeArg ( string $name )
public void getInvokeArgs ( void )
public string getModuleName ( void )
public Yaf_Request_Abstract getRequest ( void )
public Yaf_Response_Abstract getResponse ( void )
public Yaf_View_Interface getView ( void )
public void getViewpath ( void )
public void init ( void )
public void initView ([ array $options ] )
public void redirect ( string $url )
protected string render ( string $tpl [, array $parameters ] )
public void setViewpath ( string $view_directory )
}

属性

actions

你也可以通过使用这个值和 Yaf_Action_Abstract 在一个单独的PHP脚本中定义action函数。

Example #1 在一个独立的文件中定义action

<?php
class  IndexController  extends  Yaf_Controller_Abstract  {
    protected 
$actions  = array(
        

        
"dummy"  =>  "actions/Dummy_action.php" ,
    );

    

    
public  indexAction ( $name $id ) {
       
assert ( $name  ==  $this -> getRequest ()-> getParam ( "name" ));
       
assert ( $id    ==  $this -> _request -> getParam ( "id" ));
    }
}
?>

Example #2 Dummy_action.php

<?php
class  DummyAction  extends  Yaf_Action_Abstract  {
    

    
public  execute () {
    }
}
?>
_module

模块名

_name

_request

当前的请求实例

_response

_invoke_args

_view

视图引擎

Table of Contents

  • Yaf_Controller_Abstract::__clone — Yaf_Controller_Abstract 不能被克隆
  • Yaf_Controller_Abstract::__construct — Yaf_Controller_Abstract constructor
  • Yaf_Controller_Abstract::display — The display purpose
  • Yaf_Controller_Abstract::forward — The forward purpose
  • Yaf_Controller_Abstract::getInvokeArg — The getInvokeArg purpose
  • Yaf_Controller_Abstract::getInvokeArgs — The getInvokeArgs purpose
  • Yaf_Controller_Abstract::getModuleName — 获取当前控制器所属的模块名
  • Yaf_Controller_Abstract::getRequest — The getRequest purpose
  • Yaf_Controller_Abstract::getResponse — The getResponse purpose
  • Yaf_Controller_Abstract::getView — 获取当前的视图引擎
  • Yaf_Controller_Abstract::getViewpath — The getViewpath purpose
  • Yaf_Controller_Abstract::init — 控制器初始化
  • Yaf_Controller_Abstract::initView — The initView purpose
  • Yaf_Controller_Abstract::redirect — The redirect purpose
  • Yaf_Controller_Abstract::render — 渲染视图模板
  • Yaf_Controller_Abstract::setViewpath — The setViewpath purpose
上一篇: 下一篇: