Book/yaf-Phpdoc专题
Yet Another Framework
目录
- 简介
- 安装/配置
- 预定义常量
- 范例
- 应用配置
- Yaf_Application — The
Yaf_Application class
- Yaf_Application::app — 获取当前的Yaf_Application实例
- Yaf_Application::bootstrap — 调用bootstrap
- Yaf_Application::clearLastError — 清除最后的错误信息
- Yaf_Application::__construct — Yaf_Application的构造函数
- Yaf_Application::__destruct — 析构函数
- Yaf_Application::environ — 获取当前Yaf_Application的环境名
- Yaf_Application::execute — 运行回调函数
- Yaf_Application::getAppDirectory — 获取应用的目录
- Yaf_Application::getConfig — 获取 Yaf_Config_Abstract 的实例
- Yaf_Application::getDispatcher — 获取 Yaf_Dispatcher 的实例
- Yaf_Application::getLastErrorMsg — 获取最近产生的错误的错误信息
- Yaf_Application::getLastErrorNo — 获取最后产生的错误的错误代码
- Yaf_Application::getModules — 获取在配置文件中申明的模块
- Yaf_Application::run — 运行 Yaf_Application
- Yaf_Application::setAppDirectory — 改变应用目录
- Yaf_Bootstrap_Abstract — The Yaf_Bootstrap_Abstract class
- Yaf_Dispatcher — Yaf_Dispatcher 类
- Yaf_Dispatcher::autoRender — 开启/关闭自动渲染功能
- Yaf_Dispatcher::catchException — 开启/关闭自动异常捕获功能
- Yaf_Dispatcher::__construct — Yaf_Dispatcher 构造函数
- Yaf_Dispatcher::disableView — 关闭自动渲染
- Yaf_Dispatcher::dispatch — 分发请求
- Yaf_Dispatcher::enableView — 开启自动渲染
- Yaf_Dispatcher::flushInstantly — 打开关闭自动响应
- Yaf_Dispatcher::getApplication — 获取当前的Yaf_Application实例
- Yaf_Dispatcher::getDefaultAction — Retrive the default action name
- Yaf_Dispatcher::getDefaultController — Retrive the default controller name
- Yaf_Dispatcher::getDefaultModule — Retrive the default module name
- Yaf_Dispatcher::getInstance — 获取当前的Yaf_Dispatcher实例
- Yaf_Dispatcher::getRequest — 获取当前的请求实例
- Yaf_Dispatcher::getRouter — 获取路由器
- Yaf_Dispatcher::initView — 初始化视图引擎并返回它
- Yaf_Dispatcher::registerPlugin — 注册一个插件
- Yaf_Dispatcher::returnResponse — The returnResponse purpose
- Yaf_Dispatcher::setDefaultAction — 设置路由的默认动作
- Yaf_Dispatcher::setDefaultController — 设置路由的默认控制器
- Yaf_Dispatcher::setDefaultModule — 设置路由的默认模块
- Yaf_Dispatcher::setErrorHandler — 设置错误处理函数
- Yaf_Dispatcher::setRequest — The setRequest purpose
- Yaf_Dispatcher::setView — 设置视图引擎
- Yaf_Dispatcher::throwException — 开启/关闭异常抛出
- Yaf_Config_Abstract — The
Yaf_Config_Abstract class
- Yaf_Config_Abstract::get — Getter
- Yaf_Config_Abstract::readonly — 寻找只读配置
- Yaf_Config_Abstract::set — Setter
- Yaf_Config_Abstract::toArray — 转换为数组
- Yaf_Config_Ini — The
Yaf_Config_Ini class
- Yaf_Config_Ini::__construct — 构造函数
- Yaf_Config_Ini::count — 返回配置的节数量
- Yaf_Config_Ini::current — 返回当前节点
- Yaf_Config_Ini::__get — 读取节点配置
- Yaf_Config_Ini::__isset — 检查节点是否存在
- Yaf_Config_Ini::key — 返回当前元素的键
- Yaf_Config_Ini::next — 向前移动到下一个元素
- Yaf_Config_Ini::offsetExists — 检查一个偏移位置是否存在
- Yaf_Config_Ini::offsetGet — 获取一个偏移位置的值
- Yaf_Config_Ini::offsetSet — 设置一个偏移位置的值
- Yaf_Config_Ini::offsetUnset — 复位一个偏移位置的值
- Yaf_Config_Ini::readonly — 检查配置是否只读
- Yaf_Config_Ini::rewind — 检查当前位置是否有效
- Yaf_Config_Ini::__set — The __set purpose
- Yaf_Config_Ini::toArray — 转换为数组的格式
- Yaf_Config_Ini::valid — 检查迭代器是否有效
- Yaf_Config_Simple — The
Yaf_Config_Simple class
- Yaf_Config_Simple::__construct — 构造函数
- Yaf_Config_Simple::count — 返回配置的节数量
- Yaf_Config_Simple::current — 返回当前节点
- Yaf_Config_Simple::__get — 读取节点配置
- Yaf_Config_Simple::__isset — 检查节点是否存在
- Yaf_Config_Simple::key — 返回当前元素的键
- Yaf_Config_Simple::next — 向前移动到下一个元素
- Yaf_Config_Simple::offsetExists — 检查一个偏移位置是否存在
- Yaf_Config_Simple::offsetGet — 获取一个偏移位置的值
- Yaf_Config_Simple::offsetSet — 设置一个偏移位置的值
- Yaf_Config_Simple::offsetUnset — 复位一个偏移位置的值
- Yaf_Config_Simple::readonly — 检查配置是否只读
- Yaf_Config_Simple::rewind — 检查当前位置是否有效
- Yaf_Config_Simple::__set — 设置节点配置
- Yaf_Config_Simple::toArray — 转换为数组的格式
- Yaf_Config_Simple::valid — 检查迭代器是否有效
- Yaf_Controller_Abstract —
The Yaf_Controller_Abstract class
- 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::getName — Get self name
- 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
- Yaf_Action_Abstract — The
Yaf_Action_Abstract class
- Yaf_Action_Abstract::execute — 执行动作
- Yaf_Action_Abstract::getController — 得到控制器实例
- Yaf_Action_Abstract::getControllerName — Get controller name
- Yaf_View_Interface — The
Yaf_View_Interface class
- Yaf_View_Interface::assign — 为视图引擎分配一个模板变量
- Yaf_View_Interface::display — 渲染一个视图模板, 并直接输出给请求端
- Yaf_View_Interface::getScriptPath — The getScriptPath purpose
- Yaf_View_Interface::render — 渲染一个视图模板
- Yaf_View_Interface::setScriptPath — The setScriptPath purpose
- Yaf_View_Simple — The
Yaf_View_Simple Class
- Yaf_View_Simple::assign — 为视图引擎分配一个模板变量
- Yaf_View_Simple::assignRef — The assignRef purpose
- Yaf_View_Simple::clear — Clear Assigned values
- Yaf_View_Simple::__construct — Constructor of Yaf_View_Simple
- Yaf_View_Simple::display — 渲染一个视图模板, 并直接输出给请求端
- Yaf_View_Simple::eval — 渲染模板
- Yaf_View_Simple::__get — 获取视图引擎的一个模板变量值
- Yaf_View_Simple::getScriptPath — 获取模板目录
- Yaf_View_Simple::__isset — The __isset purpose
- Yaf_View_Simple::render — 渲染模板
- Yaf_View_Simple::__set — 为视图引擎分配一个模板变量
- Yaf_View_Simple::setScriptPath — 设置模板的目录
- Yaf_Loader — The Yaf_Loader class
- Yaf_Loader::autoload — The autoload purpose
- Yaf_Loader::clearLocalNamespace — The clearLocalNamespace purpose
- Yaf_Loader::__construct — The __construct purpose
- Yaf_Loader::getInstance — The getInstance purpose
- Yaf_Loader::getLibraryPath — get the library path
- Yaf_Loader::getLocalNamespace — The getLocalNamespace purpose
- Yaf_Loader::getNamespacePath — Retieve path of a registered namespace
- Yaf_Loader::getLocalNamespace — Retrive all register namespaces info
- Yaf_Loader::import — The import purpose
- Yaf_Loader::isLocalName — The isLocalName purpose
- Yaf_Loader::registerLocalNamespace — 注册本地类前缀
- Yaf_Loader::registerNamespace — Register namespace with searching path
- Yaf_Loader::setLibraryPath — 改变library路径
- Yaf_Plugin_Abstract — The
Yaf_Plugin_Abstract class
- Yaf_Plugin_Abstract::dispatchLoopShutdown — The dispatchLoopShutdown purpose
- Yaf_Plugin_Abstract::dispatchLoopStartup — The dispatchLoopStartup purpose
- Yaf_Plugin_Abstract::postDispatch — The postDispatch purpose
- Yaf_Plugin_Abstract::preDispatch — The preDispatch purpose
- Yaf_Plugin_Abstract::preResponse — The preResponse purpose
- Yaf_Plugin_Abstract::routerShutdown — The routerShutdown purpose
- Yaf_Plugin_Abstract::routerStartup — RouterStartup hook
- Yaf_Registry — The Yaf_Registry class
- Yaf_Registry::__construct — Yaf_Registry implements singleton
- Yaf_Registry::del — Remove an item from registry
- Yaf_Registry::get — Retrieve an item from registry
- Yaf_Registry::has — Check whether an item exists
- Yaf_Registry::set — Add an item into registry
- Yaf_Request_Abstract — The
Yaf_Request_Abstract class
- Yaf_Request_Abstract::clearParams — Remove all params
- Yaf_Request_Abstract::getActionName — The getActionName purpose
- Yaf_Request_Abstract::getBaseUri — The getBaseUri purpose
- Yaf_Request_Abstract::getControllerName — The getControllerName purpose
- Yaf_Request_Abstract::getEnv — 取得ENV变量的值
- Yaf_Request_Abstract::getException — The getException purpose
- Yaf_Request_Abstract::getLanguage — The getLanguage purpose
- Yaf_Request_Abstract::getMethod — The getMethod purpose
- Yaf_Request_Abstract::getModuleName — The getModuleName purpose
- Yaf_Request_Abstract::getParam — The getParam purpose
- Yaf_Request_Abstract::getParams — The getParams purpose
- Yaf_Request_Abstract::getRequestUri — The getRequestUri purpose
- Yaf_Request_Abstract::getServer — 返回SERVER变量的值
- Yaf_Request_Abstract::isCli — The isCli purpose
- Yaf_Request_Abstract::isDispatched — The isDispatched purpose
- Yaf_Request_Abstract::isGet — The isGet purpose
- Yaf_Request_Abstract::isHead — The isHead purpose
- Yaf_Request_Abstract::isOptions — The isOptions purpose
- Yaf_Request_Abstract::isPost — The isPost purpose
- Yaf_Request_Abstract::isPut — The isPut purpose
- Yaf_Request_Abstract::isRouted — The isRouted purpose
- Yaf_Request_Abstract::isXmlHttpRequest — The isXmlHttpRequest purpose
- Yaf_Request_Abstract::setActionName — The setActionName purpose
- Yaf_Request_Abstract::setBaseUri — The setBaseUri purpose
- Yaf_Request_Abstract::setControllerName — The setControllerName purpose
- Yaf_Request_Abstract::setDispatched — The setDispatched purpose
- Yaf_Request_Abstract::setModuleName — The setModuleName purpose
- Yaf_Request_Abstract::setParam — The setParam purpose
- Yaf_Request_Abstract::setRequestUri — The setRequestUri purpose
- Yaf_Request_Abstract::setRouted — The setRouted purpose
- Yaf_Request_Http — The
Yaf_Request_Http class
- Yaf_Request_Http::__construct — The __construct purpose
- Yaf_Request_Http::get — 从客户端返回变量
- Yaf_Request_Http::getCookie — 返回Cookie变量
- Yaf_Request_Http::getFiles — The getFiles purpose
- Yaf_Request_Http::getPost — 返回POST变量
- Yaf_Request_Http::getQuery — fetch a query parameter
- Yaf_Request_Http::getRaw — Retrieve Raw request body
- Yaf_Request_Http::getRequest — The getRequest purpose
- Yaf_Request_Http::isXmlHttpRequest — 是否为Ajax请求
- Yaf_Request_Simple — The
Yaf_Request_Simple class
- Yaf_Request_Simple::__construct — The __construct purpose
- Yaf_Request_Simple::get — The get purpose
- Yaf_Request_Simple::getCookie — The getCookie purpose
- Yaf_Request_Simple::getFiles — The getFiles purpose
- Yaf_Request_Simple::getPost — The getPost purpose
- Yaf_Request_Simple::getQuery — The getQuery purpose
- Yaf_Request_Simple::getRequest — The getRequest purpose
- Yaf_Request_Simple::isXmlHttpRequest — The isXmlHttpRequest purpose
- Yaf_Response_Abstract — The
Yaf_Response_Abstract class
- Yaf_Response_Abstract::appendBody — 往已有的响应body后附加新的内容
- Yaf_Response_Abstract::clearBody — 清除已经设置的响应body
- Yaf_Response_Abstract::clearHeaders — The clearHeaders purpose
- Yaf_Response_Abstract::__construct — The __construct purpose
- Yaf_Response_Abstract::__destruct — The __destruct purpose
- Yaf_Response_Abstract::getBody — 获取已经设置的响应body
- Yaf_Response_Abstract::getHeader — The getHeader purpose
- Yaf_Response_Abstract::prependBody — The prependBody purpose
- Yaf_Response_Abstract::response — send response
- Yaf_Response_Abstract::setAllHeaders — The setAllHeaders purpose
- Yaf_Response_Abstract::setBody — 设置响应的Body
- Yaf_Response_Abstract::setHeader — The setHeader purpose
- Yaf_Response_Abstract::setRedirect — The setRedirect purpose
- Yaf_Response_Abstract::__toString — The __toString purpose
- Yaf_Route_Interface — The
Yaf_Route_Interface class
- Yaf_Route_Interface::assemble — 将指定路由规则组合成一个url
- Yaf_Route_Interface::route — route a request
- Yaf_Route_Map — The Yaf_Route_Map
class
- Yaf_Route_Map::assemble — 组合url
- Yaf_Route_Map::__construct — The __construct purpose
- Yaf_Route_Map::route — The route purpose
- Yaf_Route_Regex — The
Yaf_Route_Regex class
- Yaf_Route_Regex::assemble — 组合url
- Yaf_Route_Regex::__construct — The __construct purpose
- Yaf_Route_Regex::route — The route purpose
- Yaf_Route_Rewrite — The
Yaf_Route_Rewrite class
- Yaf_Route_Rewrite::assemble — 组合url
- Yaf_Route_Rewrite::__construct — The __construct purpose
- Yaf_Route_Rewrite::route — The route purpose
- Yaf_Router — The Yaf_Router class
- Yaf_Router::addConfig — 向Router中添加配置文件中定义的路由
- Yaf_Router::addRoute — 往Router中添加新的路由
- Yaf_Router::__construct — Yaf_Router constructor
- Yaf_Router::getCurrentRoute — 取得当前有效的路由名
- Yaf_Router::getRoute — The getRoute purpose
- Yaf_Router::getRoutes — The getRoutes purpose
- Yaf_Router::route — The route purpose
- Yaf_Route_Simple — The
Yaf_Route_Simple class
- Yaf_Route_Simple::assemble — 组合url
- Yaf_Route_Simple::__construct — Yaf_Route_Simple constructor
- Yaf_Route_Simple::route — Route a request
- Yaf_Route_Static — The
Yaf_Route_Static class
- Yaf_Route_Static::assemble — 组合url
- Yaf_Route_Static::match — The match purpose
- Yaf_Route_Static::route — Route a request
- Yaf_Route_Supervar — The
Yaf_Route_Supervar class
- Yaf_Route_Supervar::assemble — 组合url
- Yaf_Route_Supervar::__construct — The __construct purpose
- Yaf_Route_Supervar::route — The route purpose
- Yaf_Session — The Yaf_Session class
- Yaf_Session::__construct — The __construct purpose
- Yaf_Session::count — The count purpose
- Yaf_Session::current — The current purpose
- Yaf_Session::del — The del purpose
- Yaf_Session::__get — The __get purpose
- Yaf_Session::getInstance — The getInstance purpose
- Yaf_Session::has — The has purpose
- Yaf_Session::__isset — The __isset purpose
- Yaf_Session::key — The key purpose
- Yaf_Session::next — The next purpose
- Yaf_Session::offsetExists — The offsetExists purpose
- Yaf_Session::offsetGet — The offsetGet purpose
- Yaf_Session::offsetSet — The offsetSet purpose
- Yaf_Session::offsetUnset — The offsetUnset purpose
- Yaf_Session::rewind — The rewind purpose
- Yaf_Session::__set — The __set purpose
- Yaf_Session::start — The start purpose
- Yaf_Session::__unset — The __unset purpose
- Yaf_Session::valid — The valid purpose
- Yaf_Exception — The Yaf_Exception
class
- Yaf_Exception::__construct — The __construct purpose
- Yaf_Exception::getPrevious — The getPrevious purpose
- Yaf_Exception_TypeError — The Yaf_Exception_TypeError class
- Yaf_Exception_StartupError — The Yaf_Exception_StartupError class
- Yaf_Exception_DispatchFailed — The Yaf_Exception_DispatchFailed class
- Yaf_Exception_RouterFailed — The Yaf_Exception_RouterFailed class
- Yaf_Exception_LoadFailed — The Yaf_Exception_LoadFailed class
- Yaf_Exception_LoadFailed_Module — The Yaf_Exception_LoadFailed_Module class
- Yaf_Exception_LoadFailed_Controller — The Yaf_Exception_LoadFailed_Controller class
- Yaf_Exception_LoadFailed_Action — The Yaf_Exception_LoadFailed_Action class
- Yaf_Exception_LoadFailed_View — The Yaf_Exception_LoadFailed_View class
简介
<span class="classname">Yaf_Application为应用提供了一个辅助设施。 它提供了可重用的资源,常见的和模块化的引导类,还有依赖的检查。
Note:
Yaf_Application实现了单例模式。 <span class="classname">Yaf_Application不能够被序列化和反序列化, 因为当你尝试使用PHPUnit来为Yaf写一些测试用例的时候会造成一些不必要的麻烦。
你可以使用PHPUnit的@backupGlobals注释来控制全局变量的备份和恢复操作, 从而可以解决这个问题。
类摘要
Yaf_Application
final class Yaf_Application {
/* 属性 */
protected $config
;
protected $dispatcher
;
protected <span
class="modifier">static $_app
;
protected $_modules
;
protected $_running
;
protected $_environ
;
/* 方法 */
public <span class="modifier">static void <span class="methodname">app ( void )
public void
bootstrap ([ <span
class="methodparam">Yaf_Bootstrap_Abstract
$bootstrap
] )
public <span class="type">Yaf_Application <span class="methodname">clearLastError ( <span class="methodparam">void )
public <span
class="methodname">__construct ( <span
class="methodparam">mixed $config
[,
string
$envrion
] )
public void __destruct ( <span class="methodparam">void )
public void environ ( <span class="methodparam">void )
public void
execute ( <span
class="methodparam">callable $entry
,
string $...
)
public <span class="type">Yaf_Application <span class="methodname">getAppDirectory ( <span class="methodparam">void )
public <span class="type">Yaf_Config_Abstract <span class="methodname">getConfig ( <span class="methodparam">void )
public <span class="type">Yaf_Dispatcher <span class="methodname">getDispatcher ( <span class="methodparam">void )
public string getLastErrorMsg ( <span class="methodparam">void )
public int <span class="methodname">getLastErrorNo ( <span class="methodparam">void )
public array getModules ( <span class="methodparam">void )
public void run ( <span class="methodparam">void )
public <span
class="type">Yaf_Application <span
class="methodname">setAppDirectory ( <span
class="methodparam">string $directory
)
}
属性
config
dispatcher
_app
_modules
_running
_environ
Yaf_Application::app
获取当前的Yaf_Application实例
说明
public <span class="modifier">static void <span class="methodname">Yaf_Application::app ( <span class="methodparam">void )
返回Yaf_Application的实例, 也可以使用 <span class="methodname">Yaf_Dispatcher::getApplication来得到<span class="classname">Yaf_Application的实例 <span class="methodname">Yaf_Dispatcher::getApplication.
参数
此函数没有参数。
返回值
返回值为一个Yaf_Application的实例, 如果在调用之前没有初始化一个<span class="classname">Yaf_Application实例的话,它将返回NULL
参见
- Yaf_Dispatcher::getApplication
Yaf_Application::bootstrap
调用bootstrap
说明
public void
Yaf_Application::bootstrap ([ <span
class="methodparam">Yaf_Bootstrap_Abstract
$bootstrap
] )
指示Yaf_Application去寻找Bootstrap,并按照声明的顺序,执行所有在Bootstrap类中定义的以_init开头的方法。 如果没有提供变量bootstrap,Yaf默认会去application.directory中寻找Bootstrap。
参数
bootstrap
A Yaf_Bootstrap_Abstract instance
返回值
Yaf_Application instance
范例
示例 #1 A Bootstrapexample
<?php
/**
* This file should be under the APPLICATION_PATH . "/application/"(which was defined in the config passed to Yaf_Application).
* and named Bootstrap.php, so the Yaf_Application can find it
*/
class Bootstrap extends Yaf_Bootstrap_Abstract {
function _initConfig(Yaf_Dispatcher $dispatcher) {
echo "1st called\n";
}
function _initPlugin($dispatcher) {
echo "2nd called\n";
}
}
?>
示例 #2 <span class="function">Yaf_Application::bootstrapexample
<?php
defined('APPLICATION_PATH') // APPLICATION_PATH will be used in the ini config file
|| define('APPLICATION_PATH', __DIR__)); //__DIR__ was introduced after PHP 5.3
$application = new Yaf_Application(APPLICATION_PATH.'/conf/application.ini');
$application->bootstrap();
?>
以上例程的输出类似于:
1st called
2nd called
参见
- Yaf_Bootstrap_Abstract
Yaf_Application::clearLastError
清除最后的错误信息
说明
public <span class="type">Yaf_Application <span class="methodname">Yaf_Application::clearLastError ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::clearLastErrorexample
<?php
function error_handler($errno, $errstr, $errfile, $errline) {
Yaf_Application::app()->clearLastError();
var_dump(Yaf_Application::app()->getLastErrorNo());
}
$config = array(
"application" => array(
"directory" => "/tmp/notexists",
"dispatcher" => array(
"throwException" => 0, //trigger error instead of throw exception when error occure
),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>
以上例程的输出类似于:
int(0)
Yaf_Application::__construct
Yaf_Application的构造函数
说明
public <span
class="methodname">Yaf_Application::__construct ( <span
class="methodparam">mixed $config
[,
string
$envrion
] )
初始化一个 Yaf_Application.
参数
config
关联数组的配置, 或者一个指向ini格式的配置文件的路径的字符串。
如果是一个ini配置文件,那配置文件中应该有一个定义了yaf.environ 的配置节。这个在生产环境中是默认的。
Note:
如果你使用了ini配置文件作为你应用配置的容器,你需要打开yaf.cache_config 来提升性能。
And the config entry(and there default value) list blow:
示例 #1 A ini config file example
[product]
;this one should alway be defined, and have no default value
application.directory=APPLICATION_PATH
;following configs have default value, you may no need to define them
application.library = APPLICATION_PATH . "/library"
application.dispatcher.throwException=1
application.dispatcher.catchException=1
application.baseUri=""
;the php script ext name
ap.ext=php
;the view template ext name
ap.view.ext=phtml
ap.dispatcher.defaultModuel=Index
ap.dispatcher.defaultController=Index
ap.dispatcher.defaultAction=index
;defined modules
ap.modules=Index
envrion
Which section will be loaded as the final config
返回值
范例
示例 #2 <span class="function">Yaf_Application::__constructexample
<?php
defined('APPLICATION_PATH') // APPLICATION_PATH will be used in the ini config file
|| define('APPLICATION_PATH', __DIR__)); //__DIR__ was introduced after PHP 5.3
$application = new Yaf_Application(APPLICATION_PATH.'/conf/application.ini');
$application->bootstrap()->run();
?>
以上例程的输出类似于:
示例 #3 <span class="function">Yaf_Application::__constructexample
<?php
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
$application->bootstrap()->run();
?>
以上例程的输出类似于:
参见
- Yaf_Config_Ini
Yaf_Application::__destruct
析构函数
说明
public void Yaf_Application::__destruct ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Application::environ
获取当前Yaf_Application的环境名
说明
public void Yaf_Application::environ ( <span class="methodparam">void )
返回当前Yaf_Application的环境名,它被定义在yaf.environ,默认值为"product"。
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::environexample
<?php
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
print_r($application->environ());
?>
以上例程的输出类似于:
product
Yaf_Application::execute
运行回调函数
说明
public void
Yaf_Application::execute ( <span
class="methodparam">callable $entry
,
string $...
)
这个方法通常用于在cron任务中运行Yaf_Application。 在cron任务中也可以使用autoloader和Bootstrap机制。
参数
entry
一个有效的回调函数
...
零个或者多个要传递给函数的参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::executeexample
<?php
function main($argc, $argv) {
}
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
$application->execute("main", $argc, $argv);
?>
以上例程的输出类似于:
Yaf_Application::getAppDirectory
获取应用的目录
说明
public <span class="type">Yaf_Application <span class="methodname">Yaf_Application::getAppDirectory ( <span class="methodparam">void )
参数
directory
返回值
Yaf_Application::getConfig
获取 Yaf_Config_Abstract 的实例
说明
public <span class="type">Yaf_Config_Abstract <span class="methodname">Yaf_Application::getConfig ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Config_Abstract 的实例
范例
示例 #1 <span class="function">Yaf_Application::getConfigexample
<?php
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
print_r($application->getConfig());
?>
以上例程的输出类似于:
Yaf_Config_Simple Object
(
[_config:protected] => Array
(
[application] => Array
(
[directory] => /home/laruence/local/www/htdocs/application
)
)
[_readonly:protected] => 1
)
Yaf_Application::getDispatcher
获取 Yaf_Dispatcher 的实例
说明
public <span class="type">Yaf_Dispatcher <span class="methodname">Yaf_Application::getDispatcher ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::getDispatcherexample
<?php
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
print_r($application->getDispatcher());
?>
以上例程的输出类似于:
Yaf_Dispatcher Object
(
[_router:protected] => Yaf_Router Object
(
[_routes:protected] => Array
(
[_default] => Yaf_Route_Static Object
(
)
)
[_current:protected] =>
)
[_view:protected] =>
[_request:protected] => Yaf_Request_Http Object
(
[module] =>
[controller] =>
[action] =>
[method] => Cli
[params:protected] => Array
(
)
[language:protected] =>
[_exception:protected] =>
[_base_uri:protected] =>
[uri:protected] =>
[dispatched:protected] =>
[routed:protected] =>
)
[_plugins:protected] => Array
(
)
[_auto_render:protected] => 1
[_return_response:protected] =>
[_instantly_flush:protected] =>
[_default_module:protected] => Index
[_default_controller:protected] => Index
[_default_action:protected] => index
[_response] => Yaf_Response_Cli Object
(
[_header:protected] => Array
(
)
[_body:protected] =>
[_sendheader:protected] =>
)
)
Yaf_Application::getLastErrorMsg
获取最近产生的错误的错误信息
说明
public string Yaf_Application::getLastErrorMsg ( void )
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::getLastErrorMsgexample
<?php
function error_handler($errno, $errstr, $errfile, $errline) {
var_dump(Yaf_Application::app()->getLastErrorMsg());
}
$config = array(
"application" => array(
"directory" => "/tmp/notexists",
"dispatcher" => array(
"throwException" => 0, //trigger error instead of throw exception when error occure
),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>
以上例程的输出类似于:
string(69) "Could not find controller script /tmp/notexists/controllers/Index.php"
Yaf_Application::getLastErrorNo
获取最后产生的错误的错误代码
说明
public int <span class="methodname">Yaf_Application::getLastErrorNo ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::getLastErrorNoexample
<?php
function error_handler($errno, $errstr, $errfile, $errline) {
var_dump(Yaf_Application::app()->getLastErrorNo());
var_dump(Yaf_Application::app()->getLastErrorNo() == YAF_ERR_NOTFOUND_CONTROLLER);
}
$config = array(
"application" => array(
"directory" => "/tmp/notexists",
"dispatcher" => array(
"throwException" => 0, //trigger error instead of throw exception when error occure
),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->setErrorHandler("error_handler", E_RECOVERABLE_ERROR);
$app->run();
?>
以上例程的输出类似于:
int(516)
bool(true)
Yaf_Application::getModules
获取在配置文件中申明的模块
说明
public array Yaf_Application::getModules ( <span class="methodparam">void )
获取在配置文件中声明的模块,如果没有声明,它的默认值将是"Index"。
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Application::getModulesexample
<?php
$config = array(
"application" => array(
"directory" => realpath(dirname(__FILE__)) . "/application",
),
);
/** Yaf_Application */
$application = new Yaf_Application($config);
print_r($application->getModules());
?>
以上例程的输出类似于:
Array
(
[0] => Index
)
Yaf_Application::run
运行 Yaf_Application
说明
public void Yaf_Application::run ( <span class="methodparam">void )
运行一个Yaf_Application,开始接受并处理请求,分发路由,做出相应的响应。最终将响应返回给客户端。
参数
此函数没有参数。
返回值
Yaf_Application::setAppDirectory
改变应用目录
说明
public <span
class="type">Yaf_Application <span
class="methodname">Yaf_Application::setAppDirectory ( <span
class="methodparam">string $directory
)
参数
directory
返回值
简介
Bootstrap是用来在Application运行(run)之前做一些初始化工作的机制.
你可以通过继承Yaf_Bootstrap_Abstract 来定义自己的Bootstrap类.
在Bootstrap类中所有以"_init"开头的公有的方法, 都会被按照定义顺序依次在 Yaf_Application::bootstrap 被调用的时刻调用.
范例
示例 #1 Bootstrap example
<?php
/* bootstrap class should be defined under ./application/Bootstrap.php */
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initConfig(Yaf_Dispatcher $dispatcher) {
var_dump(__METHOD__);
}
public function _initPlugin(Yaf_Dispatcher $dispatcher) {
var_dump(__METHOD__);
}
}
$config = array(
"application" => array(
"directory" => dirname(__FILE__) . "/application/",
),
);
$app = new Yaf_Application($config);
$app->bootstrap();
?>
以上例程的输出类似于:
string(22) "Bootstrap::_initConfig"
string(22) "Bootstrap::_initPlugin"
类摘要
Yaf_Bootstrap_Abstract
abstract class Yaf_Bootstrap_Abstract {
/* 属性 */
/* 方法 */
}
简介
<span class="classname">Yaf_Dispatcher用于初始化处理请求的运行环境, 它协调路由来的请求, 并分发和执行发现的动作, 然后收集动作产生的响应, 输出响应给请求者, 并在整个过程完成以后返回响应.
Yaf_Dispatcher是单例模式运行的, 也就是说自始至终只生成一个<span class="classname">Yaf_Dispatcher实例, 因此, 可以把它看成是在分发过程中生成的对象的注册表, 可以从中获取到分发过程中产生的对象.
类摘要
Yaf_Dispatcher
final class Yaf_Dispatcher {
/* 属性 */
protected $_router
;
protected $_view
;
protected $_request
;
protected $_plugins
;
protected <span
class="modifier">static $_instance
;
protected $_auto_render
;
protected $_return_response
;
protected $_instantly_flush
;
protected $_default_module
;
protected $_default_controller
;
protected $_default_action
;
/* 方法 */
public <span
class="type">Yaf_Dispatcher <span
class="methodname">autoRender ( <span
class="type">bool $flag
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">catchException ([ <span
class="methodparam">bool $flag
] )
public <span class="methodname">__construct ( <span class="methodparam">void )
public bool disableView ( <span class="methodparam">void )
public <span
class="type">Yaf_Response_Abstract <span
class="methodname">dispatch ( <span
class="type">Yaf_Request_Abstract $request
)
public <span class="type">Yaf_Dispatcher <span class="methodname">enableView ( <span class="methodparam">void )
public <span
class="type">Yaf_Dispatcher <span
class="methodname">flushInstantly ( <span
class="methodparam">bool $flag
)
public <span class="type">Yaf_Application <span class="methodname">getApplication ( <span class="methodparam">void )
public string getDefaultAction ( <span class="methodparam">void )
public string getDefaultController ( <span class="methodparam">void )
public string getDefaultModule ( <span class="methodparam">void )
public <span class="modifier">static Yaf_Dispatcher getInstance ( <span class="methodparam">void )
public <span class="type">Yaf_Request_Abstract <span class="methodname">getRequest ( <span class="methodparam">void )
public <span class="type">Yaf_Router <span class="methodname">getRouter ( <span class="methodparam">void )
public <span
class="type">Yaf_View_Interface <span
class="methodname">initView ( <span
class="type">string $templates_dir
[, <span
class="methodparam">array $options
]
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">registerPlugin ( <span
class="methodparam">Yaf_Plugin_Abstract
$plugin
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">returnResponse ( <span
class="methodparam">bool $flag
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setDefaultAction ( <span
class="methodparam">string $action
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setDefaultController ( <span
class="methodparam">string
$controller
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setDefaultModule ( <span
class="methodparam">string $module
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setErrorHandler ( <span
class="methodparam">call $callback
,
int
$error_types
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setRequest ( <span
class="type">Yaf_Request_Abstract $request
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">setView ( <span
class="type">Yaf_View_Interface $view
)
public <span
class="type">Yaf_Dispatcher <span
class="methodname">throwException ([ <span
class="methodparam">bool $flag
] )
}
属性
_router
_view
_request
_plugins
_instance
_auto_render
_return_response
_instantly_flush
_default_module
_default_controller
_default_action
Yaf_Dispatcher::autoRender
开启/关闭自动渲染功能
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::autoRender ( <span
class="methodparam">bool $flag
)
在开启的情况下(Yaf默认开启),action执行完成以后,<span
class="classname">Yaf_Dispatcher
会自动调用view引擎去渲染该action对应的视图模板。
你也可以通过调用这个函数并将 flag
参数的值设为TRUE来人工干预它。
Note:
你可以在一个action中仅仅返回FALSE来阻止当前action对应视图的自动渲染
参数
flag
bool
返回值
范例
示例 #1 <span class="function">Yaf_Dispatcher::autoRenderexample
<?php
class IndexController extends Yaf_Controller_Abstract {
/* init method will be called as soon as a controller is initialized */
public function init() {
if ($this->getRequest()->isXmlHttpRequest()) {
//do not call render for ajax request
//we will outpu a json string
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
}
}
?>
以上例程的输出类似于:
Yaf_Dispatcher::catchException
开启/关闭自动异常捕获功能
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::catchException ([ <span
class="methodparam">bool $flag
] )
当 application.dispatcher.throwException 开启的时候(你也可以通过调用 Yaf_Dispatcher::throwException(TRUE) 来开启它),Yaf将会抛出异常而不是触发异常发生。
如果开启了 <span class="methodname">Yaf_Dispatcher::catchException (可以通过设置application.dispatcher.catchException来开启),并且在你定义了异常处理的controller的情况下,Yaf会将所有未捕获的异常交给Error Controller的Error Action来处理。
参数
flag
bool
返回值
范例
示例 #1 <span class="function">Yaf_Dispatcher::catchExceptionexample
/* if you defined a ErrorController like following */
<?php
class ErrorController extends Yaf_Controller_Abstract {
/**
* you can also call to Yaf_Request_Abstract::getException to get the
* un-caught exception.
*/
public function error($exception) {
/* error occurs */
switch ($exception->getCode()) {
case YAF_ERR_NOTFOUND_MODULE:
case YAF_ERR_NOTFOUND_CONTROLLER:
case YAF_ERR_NOTFOUND_ACTION:
case YAF_ERR_NOTFOUND_VIEW:
echo 404, ":", $exception->getMessage();
break;
default :
$message = $exception->getMessage();
echo 0, ":", $exception->getMessage();
break;
}
}
}
?>
以上例程的输出类似于:
/* now if some error occur, assuming access a non-exists controller(or you can throw a exception yourself): */
404:Could not find controller script **/application/controllers/No-exists-controller.php
参见
- Yaf_Dispatcher::throwException
- Yaf_Dispatcher::setErrorHandler
Yaf_Dispatcher::__construct
Yaf_Dispatcher 构造函数
说明
public <span class="methodname">Yaf_Dispatcher::__construct ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Dispatcher::disableView
关闭自动渲染
说明
public bool Yaf_Dispatcher::disableView ( <span class="methodparam">void )
在一些用户自己会输出信息的情况下使用。
Note:
你可以在一个action中仅仅返回FALSE来阻止当前action对应视图的自动渲染
参数
此函数没有参数。
返回值
Yaf_Dispatcher::dispatch
分发请求
说明
public <span
class="type">Yaf_Response_Abstract <span
class="methodname">Yaf_Dispatcher::dispatch ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Yaf_Dispatcher 的这个方法做的工作很繁重.它需要一个request对象。
分发过程有三个不同的事件:
- 路由
- 分发
- 响应
The dispatch process has three distinct events:
- Routing
- Dispatching
- Response
路由只发生一次,当dispatch()被调用的时候,需要使用请求对象中的值。分发发生在一个循环中;一个请求可能会分发出多个action, 或者controller或者一个plugin可能重置请求对象来强制分发其他的action(参见 Yaf_Plugin_Abstract)。 当所有都执行完毕,Yaf_Dispatcher 会返回一个响应。
参数
request
返回值
Yaf_Dispatcher::enableView
开启自动渲染
说明
public <span class="type">Yaf_Dispatcher <span class="methodname">Yaf_Dispatcher::enableView ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Dispatcher::flushInstantly
打开关闭自动响应
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::flushInstantly ( <span
class="methodparam">bool $flag
)
参数
flag
返回值
Yaf_Dispatcher::getApplication
获取当前的Yaf_Application实例
说明
public <span class="type">Yaf_Application <span class="methodname">Yaf_Dispatcher::getApplication ( <span class="methodparam">void )
Retrive the Yaf_Application instance. same as Yaf_Application::app. 获取当前的Yaf_Application实例。跟 <span class="methodname">Yaf_Application::app 相同。
参数
此函数没有参数。
返回值
参见
- Yaf_Application::app
Yaf_Dispatcher::getDefaultAction
Retrive the default action name
说明
public string Yaf_Dispatcher::getDefaultAction ( void )
get the default action name
参数
此函数没有参数。
返回值
string, default action name, default is "index"
Yaf_Dispatcher::getDefaultController
Retrive the default controller name
说明
public string Yaf_Dispatcher::getDefaultController ( void )
get the default controller name
参数
此函数没有参数。
返回值
string, default controller name, default is "Index"
Yaf_Dispatcher::getDefaultModule
Retrive the default module name
说明
public string Yaf_Dispatcher::getDefaultModule ( void )
get the default module name
参数
此函数没有参数。
返回值
string, module name, default is "Index"
Yaf_Dispatcher::getInstance
获取当前的Yaf_Dispatcher实例
说明
public <span class="modifier">static Yaf_Dispatcher Yaf_Dispatcher::getInstance ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Dispatcher::getRequest
获取当前的请求实例
说明
public <span class="type">Yaf_Request_Abstract <span class="methodname">Yaf_Dispatcher::getRequest ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Dispatcher::getRouter
获取路由器
说明
public <span class="type">Yaf_Router <span class="methodname">Yaf_Dispatcher::getRouter ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Dispatcher::initView
初始化视图引擎并返回它
说明
public <span
class="type">Yaf_View_Interface <span
class="methodname">Yaf_Dispatcher::initView ( <span
class="methodparam">string
$templates_dir
[, <span
class="type">array $options
] )
参数
templates_dir
options
返回值
Yaf_Dispatcher::registerPlugin
注册一个插件
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::registerPlugin ( <span
class="methodparam">Yaf_Plugin_Abstract
$plugin
)
Yaf_Bootstrap_Abstract). 注册一个插件(参见 <span class="classname">Yaf_Plugin_Abstract)。
参数
plugin
返回值
范例
示例 #1 <span class="function">Yaf_Dispatcher::registerPluginexample
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initPlugin(Yaf_Dispatcher $dispatcher) {
/**
* Yaf assumes plugin scripts under [application.directory] . "/plugins"
* for this case, it will be:
* [application.directory] . "/plugins/" . "User" . [application.ext]
*/
$user = new UserPlugin();
$dispatcher->registerPlugin($user);
}
}
?>
参见
- Yaf_Plugin_Abstract
- Yaf_Bootstrap_Abstract
Yaf_Dispatcher::returnResponse
The returnResponse purpose
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::returnResponse ( <span
class="methodparam">bool $flag
)
参数
flag
返回值
Yaf_Dispatcher::setDefaultAction
设置路由的默认动作
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setDefaultAction ( <span
class="methodparam">string $action
)
参数
action
返回值
Yaf_Dispatcher::setDefaultController
设置路由的默认控制器
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setDefaultController ( <span
class="methodparam">string
$controller
)
参数
controller
返回值
Yaf_Dispatcher::setDefaultModule
设置路由的默认模块
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setDefaultModule ( <span
class="methodparam">string $module
)
参数
module
返回值
Yaf_Dispatcher::setErrorHandler
设置错误处理函数
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setErrorHandler ( <span
class="methodparam">call $callback
,
int
$error_types
)
设置错误处理函数,一般在application.dispatcher.throwException关闭的情况下,Yaf会在出错的时候触发错误,这个时候,如果设置了错误处理函数,则会把控制交给错误处理函数处理。
因此,当错误发生的时候这个错误处理函数将被调用。
参数
callback
错误处理的回调函数
error_types
返回值
参见
- Yaf_Dispatcher::throwException
- Yaf_Application::getLastErrorNo
- Yaf_Application::getLastErrorMsg
Yaf_Dispatcher::setRequest
The setRequest purpose
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setRequest ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
参数
plugin
返回值
Yaf_Dispatcher::setView
设置视图引擎
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::setView ( <span
class="methodparam">Yaf_View_Interface
$view
)
如果你想使用自己的视图引擎代替 <span class="classname">Yaf_View_Simple , 这个函数会帮你解决这个问题。
参数
view
A Yaf_View_Interface instance
返回值
范例
示例 #1 A custom View engineexample
<?php
require "/path/to/smarty/Smarty.class.php";
class Smarty_Adapter implements Yaf_View_Interface
{
/**
* Smarty object
* @var Smarty
*/
public $_smarty;
/**
* Constructor
*
* @param string $tmplPath
* @param array $extraParams
* @return void
*/
public function __construct($tmplPath = null, $extraParams = array()) {
$this->_smarty = new Smarty;
if (null !== $tmplPath) {
$this->setScriptPath($tmplPath);
}
foreach ($extraParams as $key => $value) {
$this->_smarty->$key = $value;
}
}
/**
* Set the path to the templates
*
* @param string $path The directory to set as the path.
* @return void
*/
public function setScriptPath($path)
{
if (is_readable($path)) {
$this->_smarty->template_dir = $path;
return;
}
throw new Exception('Invalid path provided');
}
/**
* Assign a variable to the template
*
* @param string $key The variable name.
* @param mixed $val The variable value.
* @return void
*/
public function __set($key, $val)
{
$this->_smarty->assign($key, $val);
}
/**
* Allows testing with empty() and isset() to work
*
* @param string $key
* @return boolean
*/
public function __isset($key)
{
return (null !== $this->_smarty->get_template_vars($key));
}
/**
* Allows unset() on object properties to work
*
* @param string $key
* @return void
*/
public function __unset($key)
{
$this->_smarty->clear_assign($key);
}
/**
* Assign variables to the template
*
* Allows setting a specific key to the specified value, OR passing
* an array of key => value pairs to set en masse.
*
* @see __set()
* @param string|array $spec The assignment strategy to use (key or
* array of key => value pairs)
* @param mixed $value (Optional) If assigning a named variable,
* use this as the value.
* @return void
*/
public function assign($spec, $value = null) {
if (is_array($spec)) {
$this->_smarty->assign($spec);
return;
}
$this->_smarty->assign($spec, $value);
}
/**
* Clear all assigned variables
*
* Clears all variables assigned to Yaf_View either via
* {@link assign()} or property overloading
* ({@link __get()}/{@link __set()}).
*
* @return void
*/
public function clearVars() {
$this->_smarty->clear_all_assign();
}
/**
* Processes a template and returns the output.
*
* @param string $name The template to process.
* @return string The output.
*/
public function render($name, $value = NULL) {
return $this->_smarty->fetch($name);
}
public function display($name, $value = NULL) {
echo $this->_smarty->fetch($name);
}
}
?>
示例 #2 <span class="function">Yaf_Dispatcher::setViewexample
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract {
/**
* there are some config for smarty in the config:
*
* smarty.left_delimiter = "{{"
* smarty.right_delimiter = "}}"
* smarty.template_dir = APPLICATION_PATH "/views/scripts/"
* smarty.compile_dir = APPLICATION_PATH "/views/templates_c/"
* smarty.cache_dir = APPLICATION_PATH "/views/templates_d/"
*
*/
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initLocalName() {
/** we put class Smarty_Adapter under the local library directory */
Yaf_Loader::getInstance()->registerLocalNamespace('Smarty');
}
public function _initSmarty(Yaf_Dispatcher $dispatcher) {
$smarty = new Smarty_Adapter(null, Yaf_Registry::get("config")->get("smarty"));
$dispatcher->setView($smarty);
/* now the Smarty view engine become the default view engine of Yaf */
}
}
?>
参见
- Yaf_View_Interface
- Yaf_View_Simple
Yaf_Dispatcher::throwException
开启/关闭异常抛出
说明
public <span
class="type">Yaf_Dispatcher <span
class="methodname">Yaf_Dispatcher::throwException ([ <span
class="methodparam">bool $flag
] )
当意外的错误发生的时候,开启/关闭异常抛出。 当开启的时候,Yaf将会抛出异常而不是触发可捕捉的错误。
你也可以使用 application.dispatcher.throwException来达到相同的目的。
参数
flag
bool
返回值
范例
示例 #1 <span class="function">Yaf_Dispatcher::throwexceptionexample
<?php
$config = array(
'application' => array(
'directory' => dirname(__FILE__),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->throwException(true);
try {
$app->run();
} catch (Yaf_Exception $e) {
var_dump($e->getMessage());
}
?>
以上例程的输出类似于:
string(59) "Could not find controller script /tmp/controllers/Index.php"
示例 #2 <span class="function">Yaf_Dispatcher::throwexceptionexample
<?php
$config = array(
'application' => array(
'directory' => dirname(__FILE__),
),
);
$app = new Yaf_Application($config);
$app->getDispatcher()->throwException(false);
$app->run();
?>
以上例程的输出类似于:
PHP Catchable fatal error: Yaf_Application::run(): Could not find controller script /tmp/controllers/Index.php in /tmp/1.php on line 12
参见
- Yaf_Dispatcher::catchException
- Yaf_Exception
简介
类摘要
Yaf_Config_Abstract
abstract class Yaf_Config_Abstract {
/* 属性 */
protected $_config
;
protected $_readonly
;
/* 方法 */
abstract <span
class="modifier">public mixed <span
class="methodname">get ( <span
class="type">string $name
, <span
class="methodparam">mixed $value
)
abstract <span class="modifier">public bool <span class="methodname">readonly ( <span class="methodparam">void )
abstract <span class="modifier">public <span class="type">Yaf_Config_Abstract <span class="methodname">set ( void )
abstract <span class="modifier">public array <span class="methodname">toArray ( <span class="methodparam">void )
}
属性
_config
_readonly
Yaf_Config_Abstract::get
Getter
说明
abstract <span
class="modifier">public mixed <span
class="methodname">Yaf_Config_Abstract::get ( <span
class="methodparam">string $name
,
mixed
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Abstract::readonly
寻找只读配置
说明
abstract <span class="modifier">public bool <span class="methodname">Yaf_Config_Abstract::readonly ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Abstract::set
Setter
说明
abstract <span class="modifier">public <span class="type">Yaf_Config_Abstract <span class="methodname">Yaf_Config_Abstract::set ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Abstract::toArray
转换为数组
说明
abstract <span class="modifier">public array <span class="methodname">Yaf_Config_Abstract::toArray ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
Yaf_Config_Ini允许开发者通过嵌套的对象属性语法在应用程序中用熟悉的INI格式存储和读取配置数据。 INI格式在提供拥有配置数据键的等级结构和配置数据节之间的继承能力方面具有专长。 配置数据等级结构通过用点或者句号(.)分离键值。 一个节可以扩展或者通过在节的名称之后带一个冒号(:)和被继承的配置数据的节的名称来从另一个节继承。
Note:
Yaf_Config_Ini利用PHP的函数parse_ini_file()来解析配置文件的。 请仔细查看这个函数的文档,注意它的一些特殊用途。以及它传递给Yaf_Config_Ini的一些比如 "TRUE", "FALSE","yes", "no", 和"NULL"的特殊值的处理方式
类摘要
Yaf_Config_Ini
class Yaf_Config_Ini <span class="ooclass"> extends Yaf_Config_Abstract implements Iterator <span class="oointerface">, Traversable , <span class="interfacename">ArrayAccess <span class="oointerface">, Countable {
/* 属性 */
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string
$config_file
[, <span
class="type">string $section
] )
public void count ( <span class="methodparam">void )
public void current ( <span class="methodparam">void )
public void
__get ([ <span
class="methodparam">string $name
] )
public void
__isset ( <span
class="methodparam">string $name
)
public void key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void
offsetExists ( <span
class="methodparam">string $name
)
public void
offsetGet ( <span
class="methodparam">string $name
)
public void
offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
public void
offsetUnset ( <span
class="methodparam">string $name
)
public void readonly ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
__set ( <span
class="methodparam">string $name
,
mixed
$value
)
public void toArray ( <span class="methodparam">void )
public void valid ( <span class="methodparam">void )
/* 继承的方法 */
abstract <span
class="modifier">public mixed <span
class="methodname">Yaf_Config_Abstract::get ( <span
class="methodparam">string $name
,
mixed
$value
)
abstract <span class="modifier">public bool <span class="methodname">Yaf_Config_Abstract::readonly ( <span class="methodparam">void )
abstract <span class="modifier">public <span class="type">Yaf_Config_Abstract <span class="methodname">Yaf_Config_Abstract::set ( <span class="methodparam">void )
abstract <span class="modifier">public array <span class="methodname">Yaf_Config_Abstract::toArray ( <span class="methodparam">void )
}
属性
_config
_readonly
范例
示例 #1 Yaf_Config_Iniexample
这个例子说明了使用Yaf_Config_Ini从一个INI配置文件中获取配置数据的基本用法。 这个例子中既有生产环境的配置方法也有演示环境的配置方法。 因为演示环境的配置跟生产环境的非常类似,所以演示环境的配置继承了生产环境的配置。 在复杂的情况下,决定是任意的,也可以写成相反的。在更复杂的情况下,生产环境继承自演示环境不是不可能的。 假设,以下配置数据都包含在/path/to/config.ini中:
; Production site configuration data
[production]
webhost = www.example.com
database.adapter = pdo_mysql
database.params.host = db.example.com
database.params.username = dbuser
database.params.password = secret
database.params.dbname = dbname
; Staging site configuration data inherits from production and
; overrides values as necessary
[staging : production]
database.params.host = dev.example.com
database.params.username = devuser
database.params.password = devsecret
<?php
$config = new Yaf_Config_Ini('/path/to/config.ini', 'staging');
var_dump($config->database->params->host);
var_dump($config->database->params->dbname);
var_dump($config->get("database.params.username"));
?>
以上例程的输出类似于:
string(15) "dev.example.com"
string(6) "dbname"
string(7) "devuser
Yaf_Config_Ini::__construct
构造函数
说明
public <span
class="methodname">Yaf_Config_Ini::__construct ( <span
class="methodparam">string
$config_file
[, <span
class="type">string $section
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
config_file
section
返回值
Yaf_Config_Ini::count
返回配置的节数量
说明
public void Yaf_Config_Ini::count ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::current
返回当前节点
说明
public void Yaf_Config_Ini::current ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::__get
读取节点配置
说明
public void
Yaf_Config_Ini::__get ([ <span
class="methodparam">string $name
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Ini::__isset
检查节点是否存在
说明
public void
Yaf_Config_Ini::__isset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Ini::key
返回当前元素的键
说明
public void Yaf_Config_Ini::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::next
向前移动到下一个元素
说明
public void Yaf_Config_Ini::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::offsetExists
检查一个偏移位置是否存在
说明
public void
Yaf_Config_Ini::offsetExists ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Ini::offsetGet
获取一个偏移位置的值
说明
public void
Yaf_Config_Ini::offsetGet ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Ini::offsetSet
设置一个偏移位置的值
说明
public void
Yaf_Config_Ini::offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Config_Ini::offsetUnset
复位一个偏移位置的值
说明
public void
Yaf_Config_Ini::offsetUnset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Ini::readonly
检查配置是否只读
说明
public void Yaf_Config_Ini::readonly ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::rewind
检查当前位置是否有效
说明
public void Yaf_Config_Ini::rewind ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::__set
The __set purpose
说明
public void
Yaf_Config_Ini::__set ( <span
class="methodparam">string $name
,
mixed
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Config_Ini::toArray
转换为数组的格式
说明
public void Yaf_Config_Ini::toArray ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Ini::valid
检查迭代器是否有效
说明
public void Yaf_Config_Ini::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
Yaf_Config_Simple 是 Yad_Config_ini 的简洁版本,只允许传入数组进行初始化,并提供了设置readonly的参数。
类摘要
Yaf_Config_Simple
class Yaf_Config_Simple <span class="ooclass"> extends Yaf_Config_Abstract implements Iterator <span class="oointerface">, Traversable , <span class="interfacename">ArrayAccess <span class="oointerface">, Countable {
/* 属性 */
protected $_readonly
;
/* 方法 */
public <span
class="methodname">__construct ( <span
class="methodparam">string
$config_file
[, <span
class="type">string $section
] )
public void count ( <span class="methodparam">void )
public void current ( <span class="methodparam">void )
public void
__get ([ <span
class="methodparam">string $name
] )
public void
__isset ( <span
class="methodparam">string $name
)
public void key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void
offsetExists ( <span
class="methodparam">string $name
)
public void
offsetGet ( <span
class="methodparam">string $name
)
public void
offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
public void
offsetUnset ( <span
class="methodparam">string $name
)
public void readonly ( <span class="methodparam">void )
public void rewind ( <span class="methodparam">void )
public void
__set ( <span
class="methodparam">string $name
,
string
$value
)
public void toArray ( <span class="methodparam">void )
public void valid ( <span class="methodparam">void )
/* 继承的方法 */
abstract <span
class="modifier">public mixed <span
class="methodname">Yaf_Config_Abstract::get ( <span
class="methodparam">string $name
,
mixed
$value
)
abstract <span class="modifier">public bool <span class="methodname">Yaf_Config_Abstract::readonly ( <span class="methodparam">void )
abstract <span class="modifier">public <span class="type">Yaf_Config_Abstract <span class="methodname">Yaf_Config_Abstract::set ( <span class="methodparam">void )
abstract <span class="modifier">public array <span class="methodname">Yaf_Config_Abstract::toArray ( <span class="methodparam">void )
}
属性
_config
_readonly
Yaf_Config_Simple::__construct
构造函数
说明
public <span
class="methodname">Yaf_Config_Simple::__construct ( <span
class="methodparam">string
$config_file
[, <span
class="type">string $section
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
config_file
section
返回值
Yaf_Config_Simple::count
返回配置的节数量
说明
public void Yaf_Config_Simple::count ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::current
返回当前节点
说明
public void Yaf_Config_Simple::current ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::__get
读取节点配置
说明
public void
Yaf_Config_Simple::__get ([ <span
class="methodparam">string $name
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Simple::__isset
检查节点是否存在
说明
public void
Yaf_Config_Simple::__isset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Simple::key
返回当前元素的键
说明
public void Yaf_Config_Simple::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::next
向前移动到下一个元素
说明
public void Yaf_Config_Simple::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::offsetExists
检查一个偏移位置是否存在
说明
public void
Yaf_Config_Simple::offsetExists (
string
$name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Simple::offsetGet
获取一个偏移位置的值
说明
public void
Yaf_Config_Simple::offsetGet ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Simple::offsetSet
设置一个偏移位置的值
说明
public void
Yaf_Config_Simple::offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Config_Simple::offsetUnset
复位一个偏移位置的值
说明
public void
Yaf_Config_Simple::offsetUnset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Config_Simple::readonly
检查配置是否只读
说明
public void Yaf_Config_Simple::readonly ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::rewind
检查当前位置是否有效
说明
public void Yaf_Config_Simple::rewind ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::__set
设置节点配置
说明
public void
Yaf_Config_Simple::__set ( <span
class="methodparam">string $name
,
string
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Config_Simple::toArray
转换为数组的格式
说明
public void Yaf_Config_Simple::toArray ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Config_Simple::valid
检查迭代器是否有效
说明
public void Yaf_Config_Simple::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
Yaf_Controller_Abstract 是Yaf的MVC体系的核心部分。 MVC是指Model-View-Controller, 是一个用于分离应用逻辑和表现逻辑的设计模式。
每个用户自定义controller都应当继承<span class="classname">Yaf_Controller_Abstract。
你会发现在你自己的controller中无法定义__construct方法。因此,<span class="classname">Yaf_Controller_Abstract 提供了一个魔术方法Yaf_Controller_Abstract::init()。
如果在你自己的controller里面已经定义了一个init()方法,当你的controller被实例化的时候,它将被调用。
Action可能需要参数,当一个请求来到的时候,在路由中如果请求的参数有相同名称的变量(例如: Yaf_Request_Abstract::getParam), Yaf将把他们传递给action方法(see <span class="methodname">Yaf_Action_Abstract::execute)。
类摘要
Yaf_Controller_Abstract
abstract class Yaf_Controller_Abstract {
/* 属性 */
public $actions
;
protected $_module
;
protected $_name
;
protected $_request
;
protected $_response
;
protected $_invoke_args
;
protected $_view
;
/* 方法 */
final <span class="modifier">private <span class="methodname">__construct ( <span class="methodparam">void )
protected bool
display ( <span
class="methodparam">string $tpl
[,
array
$parameters
] )
public void
forward ( <span
class="methodparam">string $module
[, string
$controller
[, <span
class="type">string $action
[, <span
class="methodparam">array $paramters
]]] )
public void
getInvokeArg ( <span
class="methodparam">string $name
)
public void getInvokeArgs ( <span class="methodparam">void )
public string getModuleName ( <span class="methodparam">void )
public string getName ( <span class="methodparam">void )
public <span class="type">Yaf_Request_Abstract <span class="methodname">getRequest ( <span class="methodparam">void )
public <span class="type">Yaf_Response_Abstract <span class="methodname">getResponse ( <span class="methodparam">void )
public <span class="type">Yaf_View_Interface <span class="methodname">getView ( <span class="methodparam">void )
public void getViewpath ( <span class="methodparam">void )
public void init ( <span class="methodparam">void )
public void
initView ([ <span
class="methodparam">array $options
]
)
public void
redirect ( <span
class="methodparam">string $url
)
protected string
render ( <span
class="type">string $tpl
[, <span
class="methodparam">array $parameters
] )
public void
setViewpath ( <span
class="methodparam">string
$view_directory
)
}
属性
actions
你也可以通过使用这个值和 <span
class="classname">Yaf_Action_Abstract
在一个单独的PHP脚本中定义action函数。
示例 #1 在一个独立的文件中定义action
<?php
class 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) {
assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->_request->getParam("id"));
}
}
?>
示例 #2 Dummy_action.php
<?php
class 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 constructor
说明
final <span class="modifier">private <span class="methodname">Yaf_Controller_Abstract::__construct ( void )
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::display
The display purpose
说明
protected bool
Yaf_Controller_Abstract::display (
string $tpl
[, array
$parameters
] )
参数
tpl
parameters
返回值
Yaf_Controller_Abstract::forward
The forward purpose
说明
public void
Yaf_Controller_Abstract::forward (
string
$module
[, <span
class="type">string $controller
[, <span
class="methodparam">string $action
[, array
$paramters
]]] )
将当前的请求转交给另外的Action.
Note:
调用 <span class="methodname">Yaf_Controller_Abstract::forward以后, 不会直接立即跳转到目的Action执行, 而是会在当前的Action执行完成后, 下一轮的DispatchLoop中, 交给目的Action.
所以, 如果你希望立即跳转到目的Action, 那么请使用return结束当前的执行流程.
参数
module
要跳转的目的Action的Module, 如果是NULL, 则默认Module会被采用.
controller
要跳转的目的Action的Controller, 如果是NULL, 则默认Controller会被采用.
action
要跳转的目的Action.
paramters
跳转参数, 可以在目的Action中通过 <span
class="methodname">Yaf_Request_Abstrace::getParam来获取.
范例
示例 #1 <span class="function">Yaf_Controller_Abstract::forward例子
<?php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction(){
$logined = $_SESSION["login"];
if (!$logined) {
$this->forward("login", array("from" => "Index")); // 跳转到login Action
return FALSE; // return立即结束当前的执行流程, 跳转到目的Action
// 而这里的FALSE是告诉Yaf不要自动渲染这个Action的视图
}
// other processes
}
public function loginAction() {
echo "login, redirected from ", $this->_request->getParam("from") , " action";
}
}
?>
以上例程的输出类似于:
login, redirected from Index action
返回值
return FALSE on failure
参见
- Yaf_Request_Abstrace::getParam
Yaf_Controller_Abstract::getInvokeArg
The getInvokeArg purpose
说明
public void
Yaf_Controller_Abstract::getInvokeArg
( string
$name
)
参数
name
返回值
Yaf_Controller_Abstract::getInvokeArgs
The getInvokeArgs purpose
说明
public void Yaf_Controller_Abstract::getInvokeArgs ( void )
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::getModuleName
获取当前控制器所属的模块名
说明
public string Yaf_Controller_Abstract::getModuleName ( void )
获取当前控制器所属的模块名
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::getName
Get self name
说明
public string Yaf_Controller_Abstract::getName ( void )
get the controller's name
参数
此函数没有参数。
返回值
string, controller name
Yaf_Controller_Abstract::getRequest
The getRequest purpose
说明
public <span class="type">Yaf_Request_Abstract <span class="methodname">Yaf_Controller_Abstract::getRequest ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::getResponse
The getResponse purpose
说明
public <span class="type">Yaf_Response_Abstract <span class="methodname">Yaf_Controller_Abstract::getResponse ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::getView
获取当前的视图引擎
说明
public <span class="type">Yaf_View_Interface <span class="methodname">Yaf_Controller_Abstract::getView ( <span class="methodparam">void )
获取当前的视图引擎
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::getViewpath
The getViewpath purpose
说明
public void Yaf_Controller_Abstract::getViewpath ( void )
参数
此函数没有参数。
返回值
Yaf_Controller_Abstract::init
控制器初始化
说明
public void Yaf_Controller_Abstract::init ( <span class="methodparam">void )
Yaf_Controller_Abstract::__construct 是final类型,所以用户不能重载它。但是用户可以定义 <span class="methodname">Yaf_Controller_Abstract::init,该函数会在控制器对象实例化之后被调用。
参数
此函数没有参数。
返回值
参见
- <span class="methodname">Yaf_Controller_Abstract::__construct
Yaf_Controller_Abstract::initView
The initView purpose
说明
public void
Yaf_Controller_Abstract::initView ([
array
$options
] )
参数
options
返回值
Yaf_Controller_Abstract::redirect
The redirect purpose
说明
public void
Yaf_Controller_Abstract::redirect (
string $url
)
参数
url
返回值
Yaf_Controller_Abstract::render
渲染视图模板
说明
protected string
Yaf_Controller_Abstract::render (
string $tpl
[, array
$parameters
] )
参数
tpl
parameters
返回值
Yaf_Controller_Abstract::setViewpath
The setViewpath purpose
说明
public void
Yaf_Controller_Abstract::setViewpath (
string
$view_directory
)
参数
view_directory
返回值
简介
在Yaf中一个action可以采用单独定义<span class="classname">Yaf_Action_Abstract来实现。 亦即,一个action方法也可以是一个<span class="classname">Yaf_Action_Abstract的派生类
Yaf需要一个可以被它所调用的入口点(比如PHP 5.3,它有一个新的魔术方法__invoke,但是Yaf不只支持PHP 5.3+, 所以Yaf需要另一个魔术方法来执行完成这样的任务),所以在你自己的动作类里面必须要实现抽象方法 Yaf_Action_Abstract::execute
类摘要
Yaf_Action_Abstract
class Yaf_Action_Abstract <span class="ooclass"> extends Yaf_Controller_Abstract {
/* 属性 */
protected $_controller
;
/* 方法 */
abstract <span
class="modifier">publicmixed <span
class="methodname">execute ([ <span
class="type">mixed $arg
[, <span
class="methodparam">mixed $...
]] )
public<span class="type">Yaf_Controller_Abstract <span class="methodname">getController ( <span class="methodparam">void )
public string getControllerName ( <span class="methodparam">void )
/* 继承的方法 */
final <span class="modifier">private <span class="methodname">Yaf_Controller_Abstract::__construct ( void )
protected bool
Yaf_Controller_Abstract::display (
string $tpl
[, array
$parameters
] )
public void
Yaf_Controller_Abstract::forward (
string
$module
[, <span
class="type">string $controller
[, <span
class="methodparam">string $action
[, array
$paramters
]]] )
public void
Yaf_Controller_Abstract::getInvokeArg
( string
$name
)
public void Yaf_Controller_Abstract::getInvokeArgs ( void )
public string Yaf_Controller_Abstract::getModuleName ( void )
public string Yaf_Controller_Abstract::getName ( void )
public <span class="type">Yaf_Request_Abstract <span class="methodname">Yaf_Controller_Abstract::getRequest ( <span class="methodparam">void )
public <span class="type">Yaf_Response_Abstract <span class="methodname">Yaf_Controller_Abstract::getResponse ( <span class="methodparam">void )
public <span class="type">Yaf_View_Interface <span class="methodname">Yaf_Controller_Abstract::getView ( <span class="methodparam">void )
public void Yaf_Controller_Abstract::getViewpath ( void )
public void Yaf_Controller_Abstract::init ( <span class="methodparam">void )
public void
Yaf_Controller_Abstract::initView ([
array
$options
] )
public void
Yaf_Controller_Abstract::redirect (
string $url
)
protected string
Yaf_Controller_Abstract::render (
string $tpl
[, array
$parameters
] )
public void
Yaf_Controller_Abstract::setViewpath (
string
$view_directory
)
}
属性
_module
_name
_request
_response
_invoke_args
_view
_controller
Yaf_Action_Abstract::execute
执行动作
说明
abstract <span
class="modifier">publicmixed <span
class="methodname">Yaf_Action_Abstract::execute ([ <span
class="methodparam">mixed $arg
[,
mixed $...
]] )
Yaf_Action_Abstract::execute 可能会有参数
Note:
从请求返回的值可能是不安全的,在使用之前你需要对它们过滤一遍。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Action_Abstract::executeexample
<?php
/**
* A controller example
*/
class ProductController extends Yaf_Controller_Abstract {
protected $actions = array(
"index" => "actions/Index.php",
);
}
?>
示例 #2 <span class="function">Yaf_Action_Abstract::executeexample
<?php
/**
* ListAction
*/
class ListAction extends Yaf_Action_Abstract {
public function execute ($name, $id) {
assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->getRequest()->getParam("id"));
}
}
?>
以上例程的输出类似于:
/**
* Now assuming we are using the Yaf_Route_Static route
* for request: http://yourdomain/product/list/name/yaf/id/22
* will result:
*/
bool(true)
bool(true)
参见
Yaf_Action_Abstract::getController
得到控制器实例
说明
public<span class="type">Yaf_Controller_Abstract <span class="methodname">Yaf_Action_Abstract::getController ( <span class="methodparam">void )
返回控制器对象。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Action_Abstract::getControllerName
Get controller name
说明
public string Yaf_Action_Abstract::getControllerName ( void )
get the controller's name
参数
此函数没有参数。
返回值
string, controller name
简介
Yaf给用户提供一个了一个可扩展的、可自定的视图引擎接口,用户可以使用自己的视图引擎来代替Yaf内置的<span class="classname">Yaf_View_Simple。下面是一个关于怎么实现的例子,请看 Yaf_Dispatcher::setView。
类摘要
Yaf_View_Interface
class Yaf_View_Interface {
/* 方法 */
abstract <span
class="modifier">public bool <span
class="methodname">assign ( <span
class="type">string $name
[, <span
class="methodparam">string $value
]
)
abstract <span
class="modifier">public bool <span
class="methodname">display ( <span
class="type">string $tpl
[, <span
class="methodparam">array $tpl_vars
] )
abstract <span class="modifier">public void <span class="methodname">getScriptPath ( <span class="methodparam">void )
abstract <span
class="modifier">public string <span
class="methodname">render ( <span
class="type">string $tpl
[, <span
class="methodparam">array $tpl_vars
] )
abstract <span
class="modifier">public void <span
class="methodname">setScriptPath ( <span
class="methodparam">string
$template_dir
)
}
Yaf_View_Interface::assign
为视图引擎分配一个模板变量
说明
abstract <span
class="modifier">public bool <span
class="methodname">Yaf_View_Interface::assign ( <span
class="methodparam">string $name
[,
string
$value
] )
为视图引擎分配一个模板变量, 在视图模板中可以直接通过${$name}获取模板变量值
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_View_Interface::display
渲染一个视图模板, 并直接输出给请求端
说明
abstract <span
class="modifier">public bool <span
class="methodname">Yaf_View_Interface::display ( <span
class="methodparam">string $tpl
[,
array
$tpl_vars
] )
渲染一个视图模板, 并直接输出给请求端
Warning
本函数还未编写文档,仅有参数列表。
参数
tpl
tpl_vars
返回值
Yaf_View_Interface::getScriptPath
The getScriptPath purpose
说明
abstract <span class="modifier">public void <span class="methodname">Yaf_View_Interface::getScriptPath ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_View_Interface::render
渲染一个视图模板
说明
abstract <span
class="modifier">public string <span
class="methodname">Yaf_View_Interface::render ( <span
class="methodparam">string $tpl
[,
array
$tpl_vars
] )
渲染一个视图模板, 得到结果
Warning
本函数还未编写文档,仅有参数列表。
参数
tpl
tpl_vars
返回值
Yaf_View_Interface::setScriptPath
The setScriptPath purpose
说明
abstract <span
class="modifier">public void <span
class="methodname">Yaf_View_Interface::setScriptPath ( <span
class="methodparam">string
$template_dir
)
设置模板的基目录,这通常通过<span class="classname">Yaf_Dispatcher调用。
Warning
本函数还未编写文档,仅有参数列表。
参数
template_dir
模板目录的绝对路径,默认的<span
class="classname">Yaf_Dispatcher会设置此目录为application.directory
. "/views".
返回值
简介
Yaf_View_Simple 这是Yaf内建的一个模板引擎,是个简单而快速的模板引擎,只支持PHP脚本
类摘要
Yaf_View_Simple
class Yaf_View_Simple <span class="oointerface">implements <span class="interfacename">Yaf_View_Interface {
/* 属性 */
protected $_tpl_vars
;
protected $_tpl_dir
;
/* 方法 */
public bool
assign ( <span
class="type">string $name
[, <span
class="methodparam">mixed $value
] )
public bool
assignRef ( <span
class="methodparam">string $name
,
mixed
&$value
)
public bool
clear ([ <span
class="methodparam">string $name
] )
final public
__construct ( <span
class="methodparam">string
$tempalte_dir
[, <span
class="type">array $options
] )
public bool
display ( <span
class="methodparam">string $tpl
[,
array
$tpl_vars
] )
public string
eval ( <span
class="type">string $tpl_content
[, <span
class="methodparam">array $tpl_vars
] )
public void
__get ([ <span
class="methodparam">string $name
] )
public string getScriptPath ( <span class="methodparam">void )
public void
__isset ( <span
class="methodparam">string $name
)
public string
render ( <span
class="type">string $tpl
[, <span
class="methodparam">array $tpl_vars
] )
public void
__set ( <span
class="methodparam">string $name
,
mixed
$value
)
public bool
setScriptPath ( <span
class="methodparam">string
$template_dir
)
}
属性
_tpl_vars
_tpl_dir
Yaf_View_Simple::assign
为视图引擎分配一个模板变量
说明
public bool
Yaf_View_Simple::assign ( <span
class="methodparam">string $name
[,
mixed
$value
] )
为视图引擎分配一个模板变量
参数
name
字符串或者数组
如果为字符串, 则$value不能为空
value
mixed value
返回值
范例
示例 #1 <span class="function">Yaf_View_Simple::assignexample
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$this->getView()->assign("foo", "bar");
$this->_view->assign( array( "key" => "value", "name" => "value"));
}
?>
示例 #2 templateexample
<html>
<head>
<title><?php echo $foo; ?></title>
</head>
<body>
<?php
foreach ($this->_tpl_vars as $name => value) {
echo $$name; // or echo $this->_tpl_vars[$name];
}
?>
</body>
</html>
参见
- Yaf_View_Simple::assignRef
- Yaf_View_Interface::clear
- Yaf_View_Simple::__set
Yaf_View_Simple::assignRef
The assignRef purpose
说明
public bool
Yaf_View_Simple::assignRef ( <span
class="methodparam">string $name
,
mixed
&$value
)
不同于 <span class="methodname">Yaf_View_Simple::assign,这个方法传递一个引用变量给模板引擎
参数
name
一个字符串的名字,被用来传递值给模板。
value
mixed value
返回值
范例
示例 #1 <span class="function">Yaf_View_Simple::assignRefexample
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$value = "bar";
$this->getView()->assign("foo", $value);
/* plz note that there was a bug before Yaf 2.1.4,
* which make following output "bar";
*/
$dummy = $this->getView()->render("index/index.phtml");
echo $value;
//prevent the auto-render
Yaf_Dispatcher::getInstance()->autoRender(FALSE);
}
?>
示例 #2 templateexample
<html>
<head>
<title><?php echo $foo; $foo = "changed"; ?></title>
</head>
<body>
</body>
</html>
以上例程的输出类似于:
/* access the index controller will result: */
changed
参见
- Yaf_View_Simple::assign
- Yaf_View_Simple::__set
Yaf_View_Simple::clear
Clear Assigned values
说明
public bool
Yaf_View_Simple::clear ([ <span
class="methodparam">string $name
] )
清除指定的变量
参数
name
分派的变量名
如果为空,将会清除所有的变量
返回值
范例
示例 #1 <span class="function">Yaf_View_Simple::clearexample
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$this->getView()->clear("foo")->clear("bar"); // clear "foo" and "bar"
$this->_view->clear(); //clear all assigned variables
}
?>
参见
- Yaf_View_Simple::assignRef
- Yaf_View_Interface::assign
- Yaf_View_Simple::__set
Yaf_View_Simple::__construct
Constructor of Yaf_View_Simple
说明
final public
Yaf_View_Simple::__construct ( <span
class="methodparam">string
$tempalte_dir
[, <span
class="type">array $options
] )
参数
tempalte_dir
模板的基本路劲,默认为APPLICATOIN . "/views"
options
Options for the engine, as of Yaf 2.1.13, you can use short tag
"<?=$var?>" in your template(regardless of "short_open_tag"),
so comes a option named "short_tag", you can switch this off
to prevent use short_tag in template.
范例
示例 #1 <span class="function">Yaf_View_Simple::__constructorexample
<?php
define ("TEMPLATE_DIRECTORY", APPLICATOIN_PATH . '/views');
$view = new Yaf_View_Simple(TEMPLATE_DIRECTORY, array(
'short_tag' => false //doesn't allow use short tag in template
));
?>
返回值
Yaf_View_Simple::display
渲染一个视图模板, 并直接输出给请求端
说明
public bool
Yaf_View_Simple::display ( <span
class="methodparam">string $tpl
[,
array
$tpl_vars
] )
渲染一个视图模板, 并直接输出给请求端
参数
tpl
tpl_vars
返回值
Yaf_View_Simple::eval
渲染模板
说明
public string
Yaf_View_Simple::eval ( <span
class="methodparam">string
$tpl_content
[, <span
class="type">array $tpl_vars
] )
渲染一个字符串模板,然后返回结果。
参数
tpl_content
string template
tpl_vars
返回值
Yaf_View_Simple::__get
获取视图引擎的一个模板变量值
说明
public void
Yaf_View_Simple::__get ([ <span
class="methodparam">string $name
] )
获取视图引擎的一个模板变量值
Note:
从2.1.11以后,参数可以为空
参数
name
分配的变量名
如果为空,所有传递的变量都会被返回
返回值
Yaf_View_Simple::getScriptPath
获取模板目录
说明
public string Yaf_View_Simple::getScriptPath ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_View_Simple::__isset
The __isset purpose
说明
public void
Yaf_View_Simple::__isset ( <span
class="methodparam">string $name
)
参数
name
返回值
Yaf_View_Simple::render
渲染模板
说明
public string
Yaf_View_Simple::render ( <span
class="methodparam">string $tpl
[,
array
$tpl_vars
] )
渲染一个视图模板, 得到结果
参数
tpl
tpl_vars
返回值
Yaf_View_Simple::__set
为视图引擎分配一个模板变量
说明
public void
Yaf_View_Simple::__set ( <span
class="methodparam">string $name
,
mixed
$value
)
这是一个更简单并且用来替代 <span class="methodname">Yaf_View_Simple::assign 的方法
参数
name
一个字符串值的名字
value
Mixed value.
返回值
范例
示例 #1 <span class="function">Yaf_View_Simple::__setexample
<?php
class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
$this->getView()->foo = "bar"; // same as assign("foo", "bar");
}
?>
参见
- Yaf_View_Simple::assignRef
- Yaf_View_Interface::assign
Yaf_View_Simple::setScriptPath
设置模板的目录
说明
public bool
Yaf_View_Simple::setScriptPath ( <span
class="methodparam">string
$template_dir
)
参数
template_dir
返回值
简介
Yaf_Loader 类为Yaf提供了自动加载功能的全面解决方案。
在第一次使用的时候,将检索 <span class="classname">Yaf_Application 的实例, <span class="classname">Yaf_Loader 实现了单利模式,并使用spl_autoload注册它自己。 通过 <span class="methodname">Yaf_Loader::getInstance 返回它的实例
Yaf_Loader 加载一个类时仅仅尝试一次,如果失败了, 后面的操作将取决于yaf.use_spl_auload, 如果这个配置项为On, <span class="methodname">Yaf_Loader::autoload 将会返回FALSE, 从而把机会让给其他的自动加载功能。如果这个配置项为Off(默认), <span class="methodname">Yaf_Loader::autoload 将会返回TRUE, 最重要的是将会抛出一个非常有用的警告(对于找出一个类加载失败非常有用)。
Note:
请保持yaf.use_spl_autoload保持关闭,除非有一些library有自己的autoload机制,并且是无法改写的。
默认情况下,Yaf_Loader 收集所有library(类定义的脚本)储存进在 php.ini(yaf.library)定义的global library directory之中。
如果你想使用 Yaf_Loader 搜索本地类(库)(定义在application.ini, 默认情况下,它是 application.directory . "/libraray"), 你需要使用 <span class="methodname">Yaf_Loader::registerLocalNameSpace 注册本地类前缀。
让我们来看看一些例子(假设 APPLICATION_PATH 是 application.directory):
示例 #1 Config example
// Assuming the following configure in php.ini:
yaf.libraray = "/global_dir"
//Assuming the following configure in application.ini
application.libraray = APPLICATION_PATH "/library"
假设以下本地名称空间已被注册:
示例 #2 注册本地命名空间
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initLoader($dispatcher) {
Yaf_Loader::getInstance()->registerLocalNameSpace(array("Foo", "Bar"));
}
?>
自动加载例子:
示例 #3 加载类
class Foo_Bar_Test =>
// APPLICATION_PATH/library/Foo/Bar/Test.php
class GLO_Name =>
// /global_dir/Glo/Name.php
class BarNon_Test
// /global_dir/Barnon/Test.php
在PHP 5.3中,你可以使用命名空间:
示例 #4 加载命名空间类
class \Foo\Bar\Dummy =>
// APPLICATION_PATH/library/Foo/Bar/Dummy.php
class \FooBar\Bar\Dummy =>
// /global_dir/FooBar/Bar/Dummy.php
你可能会注意到所有文件夹名字的首字母是大写的,你可以通过在php.ini中设置 yaf.lowcase_path = On 来将它们小写。
Yaf_Loader 也是设计来加载MVC类,响应的规则如下:
示例 #5 MVC类加载例子
Controller Classes =>
// APPLICATION_PATH/controllers/
Model Classes =>
// APPLICATION_PATH/models/
Plugin Classes =>
// APPLICATION_PATH/plugins/
Yaf 通过识别一个类的后缀(这个是默认的,你也可以通过改变配置项 yaf.name_suffix 来将它改为通过前缀识别)来决定它是否是一个MVC类:
示例 #6 MVC 类区别
Controller Classes =>
// ***Controller
Model Classes =>
// ***Model
Plugin Classes =>
// ***Plugin
some examples:
示例 #7 MVC loading example
class IndexController
// APPLICATION_PATH/controllers/Index.php
class DataModel =>
// APPLICATION_PATH/models/Data.php
class DummyPlugin =>
// APPLICATION_PATH/plugins/Dummy.php
class A_B_TestModel =>
// APPLICATION_PATH/models/A/B/Test.php
该目录将受 yaf.lowcase_path 的影响。
类摘要
Yaf_Loader
class Yaf_Loader {
/* 属性 */
protected $_local_ns
;
protected $_library
;
protected $_global_library
;
static $_instance
;
/* 方法 */
public void autoload ( <span class="methodparam">void )
public void clearLocalNamespace ( <span class="methodparam">void )
private <span class="methodname">__construct ( <span class="methodparam">void )
public <span class="modifier">static void <span class="methodname">getInstance ( <span class="methodparam">void )
public <span
class="type">Yaf_Loader <span
class="methodname">getLibraryPath ([ <span
class="methodparam">bool $is_global
<span
class="initializer"> = false ] )
public void getLocalNamespace ( <span class="methodparam">void )
public string
getNamespacePath ( <span
class="methodparam">string
$namespaces
)
public array getNamespaces ( <span class="methodparam">void )
public <span class="modifier">static void <span class="methodname">import ( void )
public void isLocalName ( <span class="methodparam">void )
public void
registerLocalNamespace ([ <span
class="methodparam">mixed $prefix
]
)
public bool
registerNamespace ( <span
class="methodparam"><span
class="type">stringarray
$namespaces
[, <span
class="type">string $path
] )
public <span
class="type">Yaf_Loader <span
class="methodname">setLibraryPath ( <span
class="methodparam">string $directory
[, bool
$is_global
= false ] )
}
属性
_local_ns
_library
默认情况下,它的值是
application.directory .
"/library", 你可以通过修改application.ini(application.library)或者调用
Yaf_Loader::setLibraryPath 改变它。
_global_library
_instance
Yaf_Loader::autoload
The autoload purpose
说明
public void Yaf_Loader::autoload ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::clearLocalNamespace
The clearLocalNamespace purpose
说明
public void Yaf_Loader::clearLocalNamespace ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::__construct
The __construct purpose
说明
private <span class="methodname">Yaf_Loader::__construct ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::getInstance
The getInstance purpose
说明
public <span class="modifier">static void <span class="methodname">Yaf_Loader::getInstance ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::getLibraryPath
get the library path
说明
public <span
class="type">Yaf_Loader <span
class="methodname">Yaf_Loader::getLibraryPath ([ <span
class="methodparam">bool $is_global
<span
class="initializer"> = false ] )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::getLocalNamespace
The getLocalNamespace purpose
说明
public void Yaf_Loader::getLocalNamespace ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::getNamespacePath
Retieve path of a registered namespace
说明
public string
Yaf_Loader::getNamespacePath ( <span
class="methodparam">string
$namespaces
)
retrieve path of a registered namespace
参数
namespace
a string of namespace.
返回值
string path, if the namespace is not
registered, then null
default library will be returned
范例
示例 #1 <span class="function">Yaf_Loader::registerNamespaceexample
<?php
$loader = Yaf_Loader::getInstance("/var/application/lib");
$loader->registerNamespace("\Vendor\PHP", "/var/lib/php");
$loader->getNamespacePath("\Vendor\PHP"); // '/var/lib/php'
$loader->getNamespacePath("\Vendor\JSP"); // '/var/application/lib'
?>
Yaf_Loader::getLocalNamespace
Retrive all register namespaces info
说明
public array Yaf_Loader::getNamespaces ( <span class="methodparam">void )
get registered namespaces info
参数
此函数没有参数。
返回值
array
Yaf_Loader::import
The import purpose
说明
public <span class="modifier">static void <span class="methodname">Yaf_Loader::import ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::isLocalName
The isLocalName purpose
说明
public void Yaf_Loader::isLocalName ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Loader::registerLocalNamespace
注册本地类前缀
说明
public void
Yaf_Loader::registerLocalNamespace ([
mixed
$prefix
] )
register local class prefix
参数
prefix
字符串或者是数组格式的类名前缀,所有拥有和这些前缀相同前缀的类将被加载到本地library路径。
返回值
bool
范例
示例 #1 <span class="function">Yaf_Loader::registerLocalNamespaceexample
<?php
$loader = Yaf_Loader::getInstance('/local/library/', '/global/library');
$loader->registerLocalNamespace("Baidu");
$loader->registerLocalNamespace(array("Sina", "Weibo");
$loader->autoload("Baidu_Name"); // search in '/local/library/'
$loader->autoload("Sina"); // search '/local/library/'
$loader->autoload("Global_Name");// search in '/global/library/'
$loader->autoload("Foo_Bar"); // search in '/global/library/'
?>
Yaf_Loader::registerNamespace
Register namespace with searching path
说明
public bool
Yaf_Loader::registerNamespace ( <span
class="methodparam"><span
class="type">stringarray
$namespaces
[, <span
class="type">string $path
] )
Register a namespace with searching path, <span class="classname">Yaf_Loader searchs classes under this namespace in path, the one is also could be configureded via application.library.directory.namespace(in application.ini);
Note:
Yaf still think underline as folder separator.
参数
namespace
a string of namespace, or a array of namespaces with paths.
path
a string of path, it it better to use abosolute path here for
performance
返回值
bool
范例
示例 #1 <span class="function">Yaf_Loader::registerNamespaceexample
<?php
$loader = Yaf_Loader::getInstance();
$loader->registerNamespace("\Vendor\PHP", "/var/lib/php");
$loader->registerNamespace(array(
"\Vendor\ASP" => "/var/lib/asp",
"\Vendor\JSP" => "/usr/lib/vendor/",
));
$loader->autoload("\Vendor\PHP\Dummy"); //load '/var/lib/php/Dummy.php'
$loader->autoload("\Vendor\PHP\Foo_Bar"); //load '/var/lib/php/Foo/Bar.php'
$loader->autoload("\Vendor\JSP\Dummy"); //load '/usr/lib/vendor/Dummy.php'
?>
Yaf_Loader::setLibraryPath
改变library路径
说明
public <span
class="type">Yaf_Loader <span
class="methodname">Yaf_Loader::setLibraryPath ( <span
class="methodparam">string $directory
[, bool
$is_global
= false ] )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
Plugins 可以让你轻松地定制和扩展框架
插件(Plugins)是一个类。 基于组件定义的类会有所变化 -- 你可能需要去实现这些接口。 但实际上,该插件(Plugin)本身就是一个类。
一个插件(plugin)会被 <span class="methodname">Yaf_Dispatcher::registerPlugin加载到Yaf框架中, 在框架注册(registerd)后,插件(plugin)类中定义方法将会在恰当的时间被该接口执行。
范例
示例 #1 Plugin example
<?php
/* bootstrap class should be defined under ./application/Bootstrap.php */
class Bootstrap extends Yaf_Bootstrap_Abstract {
public function _initPlugin(Yaf_Dispatcher $dispatcher) {
/* register a plugin */
$dispatcher->registerPlugin(new TestPlugin());
}
}
/* plugin class should be placed under ./application/plugins/ */
class TestPlugin extends Yaf_Plugin_Abstract {
public function routerStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* 在路由之前执行,这个钩子里,你可以做url重写等功能 */
var_dump("routerStartup");
}
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* 路由完成后,在这个钩子里,你可以做登陆检测等功能*/
var_dump("routerShutdown");
}
public function dispatchLoopStartup(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("dispatchLoopStartup");
}
public function preDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("preDispatch");
}
public function postDispatch(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump("postDispatch");
}
public function dispatchLoopShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
/* final hoook
in this hook user can do loging or implement layout */
var_dump("dispatchLoopShutdown");
}
}
Class IndexController extends Yaf_Controller_Abstract {
public function indexAction() {
return FALSE; //prevent rendering
}
}
$config = array(
"application" => array(
"directory" => dirname(__FILE__) . "/application/",
),
);
$app = new Yaf_Application($config);
$app->bootstrap()->run();
?>
以上例程的输出类似于:
string(13) "routerStartup"
string(14) "routerShutdown"
string(19) "dispatchLoopStartup"
string(11) "preDispatch"
string(12) "postDispatch"
string(20) "dispatchLoopShutdown"
类摘要
Yaf_Plugin_Abstract
class Yaf_Plugin_Abstract {
/* 方法 */
public void
dispatchLoopShutdown ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
dispatchLoopStartup ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
postDispatch ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
preDispatch ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
preResponse ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
routerShutdown ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
public void
routerStartup ( <span
class="methodparam">Yaf_Request_Abstract
$request
, <span
class="type">Yaf_Response_Abstract $response
)
}
Yaf_Plugin_Abstract::dispatchLoopShutdown
The dispatchLoopShutdown purpose
说明
public void
<span
class="methodname">Yaf_Plugin_Abstract::dispatchLoopShutdown (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
这个方式是Yaf插件钩子系统中最后的一个钩子,如果一个用户插件实现了这个方法,它将在分发循环结束之后触发。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
参见
- Yaf_Plugin_Abstract::routerStartup
- <span class="methodname">Yaf_Plugin_Abstract::routerShutdown
- <span class="methodname">Yaf_Plugin_Abstract::dispatchLoopStartup
- Yaf_Plugin_Abstract::preDispatch
- Yaf_Plugin_Abstract::postDispatch
Yaf_Plugin_Abstract::dispatchLoopStartup
The dispatchLoopStartup purpose
说明
public void
<span
class="methodname">Yaf_Plugin_Abstract::dispatchLoopStartup (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
这个钩子将在分发循环开始之前触发。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
Yaf_Plugin_Abstract::postDispatch
The postDispatch purpose
说明
public void
Yaf_Plugin_Abstract::postDispatch (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
Yaf_Plugin_Abstract::preDispatch
The preDispatch purpose
说明
public void
Yaf_Plugin_Abstract::preDispatch (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
Yaf_Plugin_Abstract::preResponse
The preResponse purpose
说明
public void
Yaf_Plugin_Abstract::preResponse (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
这个钩子在响应(Yaf_Response)前被触发
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
Yaf_Plugin_Abstract::routerShutdown
The routerShutdown purpose
说明
public void
Yaf_Plugin_Abstract::routerShutdown (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
这个钩子在路由结束之后触发,通常被用于登陆检查。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
范例
示例 #1 <span class="function">Yaf_Plugin_Abstract::routerShutdownexample
<?php
class UserInitPlugin extends Yaf_Plugin_Abstract {
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
$controller = $request->getControllerName();
/**
* Use access controller is unecessary for APIs
*/
if (in_array(strtolower($controller), array(
'api',
))) {
return TRUE;
}
if (Yaf_Session::getInstance()->has("login")) {
return TRUE;
}
/* Use access check failed, need to login */
$response->redirect("http://yourdomain.com/login/");
return FALSE;
}
?>
参见
- Yaf_Plugin_Abstract::routerStartup
- <span class="methodname">Yaf_Plugin_Abstract::dispatchLoopStartup
- Yaf_Plugin_Abstract::preDispatch
- Yaf_Plugin_Abstract::postDispatch
- <span class="methodname">Yaf_Plugin_Abstract::dispatchLoopShutdown
Yaf_Plugin_Abstract::routerStartup
RouterStartup hook
说明
public void
Yaf_Plugin_Abstract::routerStartup (
<span
class="type">Yaf_Request_Abstract $request
, <span
class="methodparam">Yaf_Response_Abstract
$response
)
这个是Yaf插件的勾子系统最早被触发的的一个方法,如果一个用户插件实现了这个方法,它将在路由之前触发。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
response
返回值
参见
- <span class="methodname">Yaf_Plugin_Abstract::routerShutdown
- <span class="methodname">Yaf_Plugin_Abstract::dispatchLoopStartup
- Yaf_Plugin_Abstract::preDispatch
- Yaf_Plugin_Abstract::postDispatch
- <span class="methodname">Yaf_Plugin_Abstract::dispatchLoopShutdown
简介
Yaf_Registry, 对象注册表(或称对象仓库)是一个用于在整个应用空间(application space)内存储对象和值的容器. 通过把对象存储在其中,我们可以在整个项目的任何地方使用同一个对象.这种机制相当于一种全局存储. 我们可以通过<span class="classname">Yaf_Registry类的静态方法来使用对象注册表. 另外,由于该类是一个数组对象,你可以使用数组形式来访问其中的类方法
类摘要
Yaf_Registry
class Yaf_Registry {
/* 属性 */
static $_instance
;
protected $_entries
;
/* 方法 */
__construct ( <span class="methodparam">void )
public <span
class="modifier">static void <span
class="methodname">del ( <span
class="type">string $name
)
public <span
class="modifier">static mixed <span
class="methodname">get ( <span
class="type">string $name
)
public <span
class="modifier">static bool <span
class="methodname">has ( <span
class="type">string $name
)
public <span
class="modifier">static bool <span
class="methodname">set ( <span
class="type">string $name
, <span
class="methodparam">string $value
)
}
属性
_instance
_entries
Yaf_Registry::__construct
Yaf_Registry implements singleton
说明
Yaf_Registry::__construct ( <span class="methodparam">void )
参数
此函数没有参数。
返回值
Yaf_Registry::del
Remove an item from registry
说明
public <span
class="modifier">static void <span
class="methodname">Yaf_Registry::del ( <span
class="methodparam">string $name
)
删除存在于注册表中的一个项目
参数
name
返回值
Yaf_Registry::get
Retrieve an item from registry
说明
public <span
class="modifier">static mixed <span
class="methodname">Yaf_Registry::get ( <span
class="methodparam">string $name
)
获取注册表中寄存的项
参数
name
返回值
Yaf_Registry::has
Check whether an item exists
说明
public <span
class="modifier">static bool <span
class="methodname">Yaf_Registry::has ( <span
class="methodparam">string $name
)
查询某一项目是否存在于注册表中
参数
name
返回值
Yaf_Registry::set
Add an item into registry
说明
public <span
class="modifier">static bool <span
class="methodname">Yaf_Registry::set ( <span
class="methodparam">string $name
,
string
$value
)
往全局注册表添加一个新的项
参数
name
value
返回值
简介
类摘要
Yaf_Request_Abstract
class Yaf_Request_Abstract {
/* Constants */
const string
Yaf_Request_Abstract::SCHEME_HTTP
=
http ;
const string
Yaf_Request_Abstract::SCHEME_HTTPS
=
https ;
/* 属性 */
public $module
;
public $controller
;
public $action
;
public $method
;
protected $params
;
protected $language
;
protected $_exception
;
protected $_base_uri
;
protected $uri
;
protected $dispatched
;
protected $routed
;
/* 方法 */
public bool clearParams ( <span class="methodparam">void )
public void getActionName ( <span class="methodparam">void )
public void getBaseUri ( <span class="methodparam">void )
public void getControllerName ( <span class="methodparam">void )
public void
getEnv ( <span
class="type">string $name
[, <span
class="methodparam">string $default
] )
public void getException ( <span class="methodparam">void )
public void getLanguage ( <span class="methodparam">void )
public void getMethod ( <span class="methodparam">void )
public void getModuleName ( <span class="methodparam">void )
public void
getParam ( <span
class="methodparam">string $name
[,
string
$default
] )
public void getParams ( <span class="methodparam">void )
public void getRequestUri ( <span class="methodparam">void )
public void
getServer ( <span
class="methodparam">string $name
[,
string
$default
] )
public void isCli ( <span class="methodparam">void )
public void isDispatched ( <span class="methodparam">void )
public void isGet ( <span class="methodparam">void )
public void isHead ( <span class="methodparam">void )
public void isOptions ( <span class="methodparam">void )
public void isPost ( <span class="methodparam">void )
public void isPut ( <span class="methodparam">void )
public void isRouted ( <span class="methodparam">void )
public void isXmlHttpRequest ( <span class="methodparam">void )
public void
setActionName ( <span
class="methodparam">string $action
)
public void
setBaseUri ( <span
class="methodparam">string $uir
)
public void
setControllerName ( <span
class="methodparam">string
$controller
)
public void setDispatched ( <span class="methodparam">void )
public void
setModuleName ( <span
class="methodparam">string $module
)
public void
setParam ( <span
class="methodparam">string $name
[,
string
$value
] )
public void
setRequestUri ( <span
class="methodparam">string $uir
)
public void
setRouted ([ <span
class="methodparam">string $flag
] )
}
属性
module
controller
action
method
params
language
_exception
_base_uri
uri
dispatched
routed
预定义常量
Yaf_Request_Abstract::SCHEME_HTTP
Yaf_Request_Abstract::SCHEME_HTTPS
Yaf_Request_Abstract::clearParams
Remove all params
说明
public bool Yaf_Request_Abstract::clearParams ( void )
Remove all params set by router, or <span class="methodname">Yaf_Request_Abstract::setParam
参数
此函数没有参数。
返回值
bool
参见
- Yaf_Request_Abstract::isHead
- Yaf_Request_Abstract::isGet
- Yaf_Request_Abstract::isPost
- Yaf_Request_Abstract::isPut
- Yaf_Request_Abstract::isOptions
- <span class="methodname">Yaf_Request_Abstract::isXmlHTTPRequest
Yaf_Request_Abstract::getActionName
The getActionName purpose
说明
public void Yaf_Request_Abstract::getActionName ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getBaseUri
The getBaseUri purpose
说明
public void Yaf_Request_Abstract::getBaseUri ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getControllerName
The getControllerName purpose
说明
public void <span class="methodname">Yaf_Request_Abstract::getControllerName ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getEnv
取得ENV变量的值
说明
public void
Yaf_Request_Abstract::getEnv ( <span
class="methodparam">string $name
[,
string
$default
] )
取得ENV变量的值
参数
name
the variable name
default
如果这个参数被提供了,当参数找不到的时候它将被返回
返回值
参见
- Yaf_Request_Abstract::getServer
- Yaf_Request_Abstract::getParam
Yaf_Request_Abstract::getException
The getException purpose
说明
public void Yaf_Request_Abstract::getException ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getLanguage
The getLanguage purpose
说明
public void Yaf_Request_Abstract::getLanguage ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getMethod
The getMethod purpose
说明
public void Yaf_Request_Abstract::getMethod ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getModuleName
The getModuleName purpose
说明
public void Yaf_Request_Abstract::getModuleName ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getParam
The getParam purpose
说明
public void
Yaf_Request_Abstract::getParam ( <span
class="methodparam">string $name
[,
string
$default
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
default
返回值
Yaf_Request_Abstract::getParams
The getParams purpose
说明
public void Yaf_Request_Abstract::getParams ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getRequestUri
The getRequestUri purpose
说明
public void Yaf_Request_Abstract::getRequestUri ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::getServer
返回SERVER变量的值
说明
public void
Yaf_Request_Abstract::getServer (
string
$name
[, <span
class="type">string $default
] )
返回SERVER变量的值
参数
name
the variable name
default
如果提供这个参数,在没找到变量值时候此参数的值将被返回
返回值
参见
- Yaf_Request_Abstract::getParam
- Yaf_Request_Abstract::getEnv
Yaf_Request_Abstract::isCli
The isCli purpose
说明
public void Yaf_Request_Abstract::isCli ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isDispatched
The isDispatched purpose
说明
public void Yaf_Request_Abstract::isDispatched ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isGet
The isGet purpose
说明
public void Yaf_Request_Abstract::isGet ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isHead
The isHead purpose
说明
public void Yaf_Request_Abstract::isHead ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isOptions
The isOptions purpose
说明
public void Yaf_Request_Abstract::isOptions ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isPost
The isPost purpose
说明
public void Yaf_Request_Abstract::isPost ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isPut
The isPut purpose
说明
public void Yaf_Request_Abstract::isPut ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isRouted
The isRouted purpose
说明
public void Yaf_Request_Abstract::isRouted ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::isXmlHttpRequest
The isXmlHttpRequest purpose
说明
public void Yaf_Request_Abstract::isXmlHttpRequest ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::setActionName
The setActionName purpose
说明
public void
Yaf_Request_Abstract::setActionName (
string
$action
)
Warning
本函数还未编写文档,仅有参数列表。
参数
action
返回值
Yaf_Request_Abstract::setBaseUri
The setBaseUri purpose
说明
public void
Yaf_Request_Abstract::setBaseUri (
string $uir
)
Warning
本函数还未编写文档,仅有参数列表。
参数
uir
返回值
Yaf_Request_Abstract::setControllerName
The setControllerName purpose
说明
public void
<span
class="methodname">Yaf_Request_Abstract::setControllerName (
string
$controller
)
Warning
本函数还未编写文档,仅有参数列表。
参数
controller
返回值
Yaf_Request_Abstract::setDispatched
The setDispatched purpose
说明
public void Yaf_Request_Abstract::setDispatched ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Abstract::setModuleName
The setModuleName purpose
说明
public void
Yaf_Request_Abstract::setModuleName (
string
$module
)
Warning
本函数还未编写文档,仅有参数列表。
参数
module
返回值
Yaf_Request_Abstract::setParam
The setParam purpose
说明
public void
Yaf_Request_Abstract::setParam ( <span
class="methodparam">string $name
[,
string
$value
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Request_Abstract::setRequestUri
The setRequestUri purpose
说明
public void
Yaf_Request_Abstract::setRequestUri (
string $uir
)
Warning
本函数还未编写文档,仅有参数列表。
参数
uir
返回值
Yaf_Request_Abstract::setRouted
The setRouted purpose
说明
public void
Yaf_Request_Abstract::setRouted ([
string
$flag
] )
Warning
本函数还未编写文档,仅有参数列表。
参数
flag
返回值
简介
类摘要
Yaf_Request_Http
class Yaf_Request_Http <span class="ooclass"> extends Yaf_Request_Abstract {
/* 属性 */
/* 方法 */
__construct ( <span class="methodparam">void )
public mixed
get ( <span
class="type">string $name
[, <span
class="methodparam">string $default
] )
public mixed
getCookie ( <span
class="methodparam">string $name
[,
string
$default
] )
public void getFiles ( <span class="methodparam">void )
public mixed
getPost ( <span
class="methodparam">string $name
[,
string
$default
] )
public mixed
getQuery ( <span
class="methodparam">string $name
[,
string
$default
] )
public mixed getRaw ( <span class="methodparam">void )
public void getRequest ( <span class="methodparam">void )
public bool isXmlHttpRequest ( <span class="methodparam">void )
/* 继承的方法 */
public bool Yaf_Request_Abstract::clearParams ( void )
public void Yaf_Request_Abstract::getActionName ( void )
public void Yaf_Request_Abstract::getBaseUri ( void )
public void <span class="methodname">Yaf_Request_Abstract::getControllerName ( void )
public void
Yaf_Request_Abstract::getEnv ( <span
class="methodparam">string $name
[,
string
$default
] )
public void Yaf_Request_Abstract::getException ( void )
public void Yaf_Request_Abstract::getLanguage ( void )
public void Yaf_Request_Abstract::getMethod ( void )
public void Yaf_Request_Abstract::getModuleName ( void )
public void
Yaf_Request_Abstract::getParam ( <span
class="methodparam">string $name
[,
string
$default
] )
public void Yaf_Request_Abstract::getParams ( void )
public void Yaf_Request_Abstract::getRequestUri ( void )
public void
Yaf_Request_Abstract::getServer (
string
$name
[, <span
class="type">string $default
] )
public void Yaf_Request_Abstract::isCli ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isDispatched ( void )
public void Yaf_Request_Abstract::isGet ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isHead ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isOptions ( void )
public void Yaf_Request_Abstract::isPost ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isPut ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isRouted ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isXmlHttpRequest ( void )
public void
Yaf_Request_Abstract::setActionName (
string
$action
)
public void
Yaf_Request_Abstract::setBaseUri (
string $uir
)
public void
<span
class="methodname">Yaf_Request_Abstract::setControllerName (
string
$controller
)
public void Yaf_Request_Abstract::setDispatched ( void )
public void
Yaf_Request_Abstract::setModuleName (
string
$module
)
public void
Yaf_Request_Abstract::setParam ( <span
class="methodparam">string $name
[,
string
$value
] )
public void
Yaf_Request_Abstract::setRequestUri (
string $uir
)
public void
Yaf_Request_Abstract::setRouted ([
string
$flag
] )
}
属性
module
controller
action
method
params
language
_exception
_base_uri
uri
dispatched
routed
Yaf_Request_Http::__construct
The __construct purpose
说明
Yaf_Request_Http::__construct ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Http::get
从客户端返回变量
说明
public mixed
Yaf_Request_Http::get ( <span
class="methodparam">string $name
[,
string
$default
] )
从客户端返回变量,这个方法将从请求参数中寻找参数name
,如果没有找到的话,将从POST,
GET, Cookie, Server中寻找
参数
name
the variable name
default
如果提供了此参数,当变量在未被找到的情况下,它将被返回
返回值
参见
- Yaf_Request_Http::getQuery
- Yaf_Request_Http::getPost
- Yaf_Request_Http::getCookie
- Yaf_Request_Http::getServer
- Yaf_Request_Http::getParam
Yaf_Request_Http::getCookie
返回Cookie变量
说明
public mixed
Yaf_Request_Http::getCookie ( <span
class="methodparam">string $name
[,
string
$default
] )
返回Cookie变量
参数
name
the cookie name
default
如果提供了此参数,当变量在未被找到的情况下,提供的参数将被返回
返回值
参见
- Yaf_Request_Http::get
- Yaf_Request_Http::getQuery
- Yaf_Request_Http::getPost
- Yaf_Request_Http::getServer
- Yaf_Request_Http::getParam
Yaf_Request_Http::getFiles
The getFiles purpose
说明
public void Yaf_Request_Http::getFiles ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Http::getPost
返回POST变量
说明
public mixed
Yaf_Request_Http::getPost ( <span
class="methodparam">string $name
[,
string
$default
] )
返回POST变量
参数
name
the variable name
default
如果提供了此参数,当变量在未被找到的情况下,提供的参数将被返回
返回值
参见
- Yaf_Request_Http::get
- Yaf_Request_Http::getQuery
- Yaf_Request_Http::getCookie
- Yaf_Request_Http::getServer
- Yaf_Request_Http::getParam
Yaf_Request_Http::getQuery
fetch a query parameter
说明
public mixed
Yaf_Request_Http::getQuery ( <span
class="methodparam">string $name
[,
string
$default
] )
返回Get变量
参数
name
the variable name
default
如果提供了此参数,当变量在未被找到的情况下,提供的参数将被返回
返回值
参见
- Yaf_Request_Http::get
- Yaf_Request_Http::getPost
- Yaf_Request_Http::getCookie
- Yaf_Request_Http::getServer
- Yaf_Request_Http::getParam
Yaf_Request_Http::getRaw
Retrieve Raw request body
说明
public mixed Yaf_Request_Http::getRaw ( <span class="methodparam">void )
Retrieve Raw request body
参数
此函数没有参数。
返回值
Return string on success, FALSE on failure.
参见
- Yaf_Request_Http::get
- Yaf_Request_Http::getPost
- Yaf_Request_Http::getCookie
- Yaf_Request_Http::getQuery
- Yaf_Request_Abstract::getServer
- Yaf_Request_Abstract::getParam
Yaf_Request_Http::getRequest
The getRequest purpose
说明
public void Yaf_Request_Http::getRequest ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Http::isXmlHttpRequest
是否为Ajax请求
说明
public bool Yaf_Request_Http::isXmlHttpRequest ( void )
检查请求是否是Ajax请求
Note:
这个方法取决于请求报头:HTTP_X_REQUESTED_WITH,一些Javascript库在做Ajax请求时候不设置这个报文头。
参数
此函数没有参数。
返回值
简介
Yaf_Request_Simple 特别的被用于测试。例如:CLI模式下模拟一些特殊的要求
类摘要
Yaf_Request_Simple
class Yaf_Request_Simple <span class="ooclass"> extends Yaf_Request_Abstract {
/* Constants */
const string
Yaf_Request_Simple::SCHEME_HTTP
=
http ;
const string
Yaf_Request_Simple::SCHEME_HTTPS
=
https ;
/* 属性 */
/* 方法 */
__construct ( <span class="methodparam">void )
public void get ( <span class="methodparam">void )
public void getCookie ( <span class="methodparam">void )
public void getFiles ( <span class="methodparam">void )
public void getPost ( <span class="methodparam">void )
public void getQuery ( <span class="methodparam">void )
public void getRequest ( <span class="methodparam">void )
public void isXmlHttpRequest ( <span class="methodparam">void )
/* 继承的方法 */
public bool Yaf_Request_Abstract::clearParams ( void )
public void Yaf_Request_Abstract::getActionName ( void )
public void Yaf_Request_Abstract::getBaseUri ( void )
public void <span class="methodname">Yaf_Request_Abstract::getControllerName ( void )
public void
Yaf_Request_Abstract::getEnv ( <span
class="methodparam">string $name
[,
string
$default
] )
public void Yaf_Request_Abstract::getException ( void )
public void Yaf_Request_Abstract::getLanguage ( void )
public void Yaf_Request_Abstract::getMethod ( void )
public void Yaf_Request_Abstract::getModuleName ( void )
public void
Yaf_Request_Abstract::getParam ( <span
class="methodparam">string $name
[,
string
$default
] )
public void Yaf_Request_Abstract::getParams ( void )
public void Yaf_Request_Abstract::getRequestUri ( void )
public void
Yaf_Request_Abstract::getServer (
string
$name
[, <span
class="type">string $default
] )
public void Yaf_Request_Abstract::isCli ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isDispatched ( void )
public void Yaf_Request_Abstract::isGet ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isHead ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isOptions ( void )
public void Yaf_Request_Abstract::isPost ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isPut ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isRouted ( <span class="methodparam">void )
public void Yaf_Request_Abstract::isXmlHttpRequest ( void )
public void
Yaf_Request_Abstract::setActionName (
string
$action
)
public void
Yaf_Request_Abstract::setBaseUri (
string $uir
)
public void
<span
class="methodname">Yaf_Request_Abstract::setControllerName (
string
$controller
)
public void Yaf_Request_Abstract::setDispatched ( void )
public void
Yaf_Request_Abstract::setModuleName (
string
$module
)
public void
Yaf_Request_Abstract::setParam ( <span
class="methodparam">string $name
[,
string
$value
] )
public void
Yaf_Request_Abstract::setRequestUri (
string $uir
)
public void
Yaf_Request_Abstract::setRouted ([
string
$flag
] )
}
属性
module
controller
action
method
params
language
_exception
_base_uri
uri
dispatched
routed
预定义常量
Yaf_Request_Simple::SCHEME_HTTP
Yaf_Request_Simple::SCHEME_HTTPS
Yaf_Request_Simple::__construct
The __construct purpose
说明
Yaf_Request_Simple::__construct ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::get
The get purpose
说明
public void Yaf_Request_Simple::get ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::getCookie
The getCookie purpose
说明
public void Yaf_Request_Simple::getCookie ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::getFiles
The getFiles purpose
说明
public void Yaf_Request_Simple::getFiles ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::getPost
The getPost purpose
说明
public void Yaf_Request_Simple::getPost ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::getQuery
The getQuery purpose
说明
public void Yaf_Request_Simple::getQuery ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::getRequest
The getRequest purpose
说明
public void Yaf_Request_Simple::getRequest ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Request_Simple::isXmlHttpRequest
The isXmlHttpRequest purpose
说明
public void Yaf_Request_Simple::isXmlHttpRequest ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
类摘要
Yaf_Response_Abstract
class Yaf_Response_Abstract {
/* Constants */
const string
Yaf_Response_Abstract::DEFAULT_BODY
=
"content" ;
/* 属性 */
protected $_header
;
protected $_body
;
protected $_sendheader
;
/* 方法 */
public bool
appendBody ( <span
class="methodparam">string $content
[, string
$key
] )
public bool
clearBody ([ <span
class="methodparam">string $key
] )
public void clearHeaders ( <span class="methodparam">void )
public <span class="methodname">__construct ( <span class="methodparam">void )
public void __destruct ( <span class="methodparam">void )
public mixed
getBody ([ <span
class="methodparam">string $key
] )
public void getHeader ( <span class="methodparam">void )
public bool
prependBody ( <span
class="methodparam">string $content
[, string
$key
] )
public void response ( <span class="methodparam">void )
protected void setAllHeaders ( <span class="methodparam">void )
public bool
setBody ( <span
class="methodparam">string $content
[, string
$key
] )
public void setHeader ( <span class="methodparam">void )
public void setRedirect ( <span class="methodparam">void )
private void __toString ( <span class="methodparam">void )
}
属性
_header
_body
_sendheader
Yaf_Response_Abstract::appendBody
往已有的响应body后附加新的内容
说明
public bool
Yaf_Response_Abstract::appendBody (
string
$content
[, <span
class="type">string $key
] )
往已有的响应body后附加新的内容
参数
body
content string
key
响应内容的key,你可以设置一个键值对,如果你没有具体的设置的话,系统默认使用Yaf_Response_Abstract::DEFAULT_BODY
Note:
this parameter is introduced as of 2.2.0
返回值
bool
范例
示例 #1 <span class="function">Yaf_Response_Abstract::appendBodyexample
<?php
$response = new Yaf_Response_Http();
$response->setBody("Hello")->prependBody(" World");
echo $response;
?>
以上例程的输出类似于:
Hello World
参见
- Yaf_Config_Ini
参见
- Yaf_Response_Abstract::getBody
- Yaf_Response_Abstract::setBody
- Yaf_Response_Abstract::prependBody
- Yaf_Response_Abstract::clearBody
Yaf_Response_Abstract::clearBody
清除已经设置的响应body
说明
public bool
Yaf_Response_Abstract::clearBody ([
string $key
] )
清除已经设置的响应body
参数
key
the content key, if you don't specific, then all contents will be
cleared. 如果你没选择具体清除哪个key所对应的内容,那所有内容将被清除
Note:
this parameter is introduced as of 2.2.0
返回值
参见
- Yaf_Response_Abstract::setBody
- Yaf_Response_Abstract::appendBody
- Yaf_Response_Abstract::prependBody
- Yaf_Response_Abstract::getBody
Yaf_Response_Abstract::clearHeaders
The clearHeaders purpose
说明
public void Yaf_Response_Abstract::clearHeaders ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::__construct
The __construct purpose
说明
public <span class="methodname">Yaf_Response_Abstract::__construct ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::__destruct
The __destruct purpose
说明
public void Yaf_Response_Abstract::__destruct ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::getBody
获取已经设置的响应body
说明
public mixed
Yaf_Response_Abstract::getBody ([
string $key
] )
获取已经设置的响应body
参数
key
body所对应的key,如果你没指定key,系统默认使用Yaf_Response_Abstract::DEFAULT_BODY。如果你传入一个NULL,所有的内容将会以数组形式被返回。
Note:
this parameter is introduced as of 2.2.0
返回值
范例
示例 #1 <span class="function">Yaf_Response_Abstract::getBodyexample
<?php
$response = new Yaf_Response_Http();
$response->setBody("Hello")->setBody(" World", "footer");
var_dump($response->getBody()); //default
var_dump($response->getBody(Yaf_Response_Abstract::DEFAULT_BODY)); //same as above
var_dump($response->getBody("footer"));
var_dump($response->getBody(NULL)); //get all
?>
以上例程的输出类似于:
string(5) "Hello"
string(5) "Hello"
string(6) " World"
array(2) {
["content"]=>
string(5) "Hello"
["footer"]=>
string(6) " World"
}
参见
- Yaf_Response_Abstract::setBody
- Yaf_Response_Abstract::appendBody
- Yaf_Response_Abstract::prependBody
- Yaf_Response_Abstract::clearBody
Yaf_Response_Abstract::getHeader
The getHeader purpose
说明
public void Yaf_Response_Abstract::getHeader ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::prependBody
The prependBody purpose
说明
public bool
Yaf_Response_Abstract::prependBody (
string
$content
[, <span
class="type">string $key
] )
往已有的响应body前插入新的内容
参数
body
content string
key
body所对应的key,你可以设置一个body的键值对,如果你没有指定key,系统默认使用Yaf_Response_Abstract::DEFAULT_BODY
Note:
this parameter is introduced as of 2.2.0
返回值
bool
范例
示例 #1 <span class="function">Yaf_Response_Abstract::prependBodyexample
<?php
$response = new Yaf_Response_Http();
$response->setBody("World")->prependBody("Hello ");
echo $response;
?>
以上例程的输出类似于:
Hello World
参见
- Yaf_Response_Abstract::getBody
- Yaf_Response_Abstract::setBody
- Yaf_Response_Abstract::appendBody
- Yaf_Response_Abstract::clearBody
Yaf_Response_Abstract::response
send response
说明
public void Yaf_Response_Abstract::response ( void )
send response
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Response_Abstract::responseexample
<?php
$response = new Yaf_Response_Http();
$response->setBody("Hello")->setBody(" World", "footer");
$response->response();
?>
以上例程的输出类似于:
Hello World
参见
- Yaf_Response_Abstract::setBody
- Yaf_Response_Abstract::clearBody
Yaf_Response_Abstract::setAllHeaders
The setAllHeaders purpose
说明
protected void Yaf_Response_Abstract::setAllHeaders ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::setBody
设置响应的Body
说明
public bool
Yaf_Response_Abstract::setBody ( <span
class="methodparam">string $content
[, string
$key
] )
设置响应的Body
参数
body
content string
key
body所对应的key,你可以设置一个body的键值对,如果你没有指定key,系统默认使用Yaf_Response_Abstract::DEFAULT_BODY
Note:
this parameter is introduced as of 2.2.0
返回值
范例
示例 #1 <span class="function">Yaf_Response_Abstract::setBodyexample
<?php
$response = new Yaf_Response_Http();
$response->setBody("Hello")->setBody(" World", "footer");
print_r($response);
echo $response;
?>
以上例程的输出类似于:
Yaf_Response_Http Object
(
[_header:protected] => Array
(
)
[_body:protected] => Array
(
[content] => Hello
[footer] => World
)
[_sendheader:protected] => 1
[_response_code:protected] => 200
)
Hello World
参见
- Yaf_Response_Abstract::getBody
- Yaf_Response_Abstract::appendBody
- Yaf_Response_Abstract::prependBody
- Yaf_Response_Abstract::clearBody
Yaf_Response_Abstract::setHeader
The setHeader purpose
说明
public void Yaf_Response_Abstract::setHeader ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::setRedirect
The setRedirect purpose
说明
public void Yaf_Response_Abstract::setRedirect ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Response_Abstract::__toString
The __toString purpose
说明
private void Yaf_Response_Abstract::__toString ( void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
<span class="classname">Yaf_Route_Interface是Yaf路由协议的标准接口, 它的存在使得用户可以自定义路由协议
类摘要
Yaf_Route_Interface
class Yaf_Route_Interface {
/* 方法 */
abstract <span
class="modifier">public string <span
class="methodname">assemble ( <span
class="type">array $info
[, <span
class="methodparam">array $query
] )
abstract <span
class="modifier">public bool <span
class="methodname">route ( <span
class="type">Yaf_Request_Abstract $request
)
}
Yaf_Route_Interface::assemble
将指定路由规则组合成一个url
说明
abstract <span
class="modifier">public string <span
class="methodname">Yaf_Route_Interface::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
这个方法会将指定的参数加上自定义的参数组合成一个url
所有route必须结合其路由规则来实现这个方法
参数
info
query
返回值
Yaf_Route_Interface::route
route a request
说明
abstract <span
class="modifier">public bool <span
class="methodname">Yaf_Route_Interface::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Yaf_Route_Interface::route 是用户自定义路由唯一需要实现的方法。
如果这个方法返回TRUE,那么路由进程将会中止。否则,<span class="classname">Yaf_Router 将会调用路由堆栈中的下一个路由来路由请求。
这个方法会设置路由的结果给参数请求,通过调用 <span class="methodname">Yaf_Request_Abstract::setControllerName, Yaf_Request_Abstract::setActionName 和 Yaf_Request_Abstract::setModuleName
这个方法也需要调用 <span class="methodname">Yaf_Request_Abstract::setRouted做最后的请求路由。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
A Yaf_Request_Abstract instance.
返回值
简介
类摘要
Yaf_Route_Map
class Yaf_Route_Map <span class="oointerface">implements <span class="interfacename">Yaf_Route_Interface {
/* 属性 */
protected $_ctl_router
;
protected $_delimeter
;
/* 方法 */
public string
assemble (
array $info
[, <span
class="methodparam"> array $query
]
)
public <span
class="methodname">__construct ([ <span
class="methodparam">string
$controller_prefer
= false [,
string
$delimiter
= '' ]] )
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
}
属性
_ctl_router
_delimeter
Yaf_Route_Map::assemble
组合url
说明
public string
Yaf_Route_Map::assemble ( <span
class="methodparam"> array $info
[,
array $query
] )
根据指定参数和自定义参数将map这个route组合成一个url
参数
info
需要传入一个数组,数组的key可以为:a或者:c,:a表示action,:c表示controller。
当map route初始化时,controller_prefer为false时,这个参数需要传入:c。当controller_prefer 为true时,这个参数需要传入:a。
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Map::assembleexample
<?php
$router = new Yaf_Router();
$route = new Yaf_Route_Map();
$router->addRoute("map", $route);
var_dump($router->getRoute('map')->assemble(
array(
':c' => 'foo_bar'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
)
);
$route = new Yaf_Route_Map(true, '_');
$router->addRoute("map", $route);
var_dump($router->getRoute('map')->assemble(
array(
':a' => 'foo_bar'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
)
);
以上例程的输出类似于:
string(%d) "/foo/bar?tkey1=tval1&tkey2=tval2"
string(%d) "/foo/bar/_/tkey1/tval1/tkey2/tval2"
返回值
Yaf_Route_Map::__construct
The __construct purpose
说明
public <span
class="methodname">Yaf_Route_Map::__construct ([ <span
class="methodparam">string
$controller_prefer
= false [,
string
$delimiter
= '' ]] )
Warning
本函数还未编写文档,仅有参数列表。
参数
controller_prefer
结果是否应该考虑作为controller或action
delimiter
返回值
范例
示例 #1 Yaf_Route_Mapexample
<?php
/**
* Add a map route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Map());
?>
以上例程的输出类似于:
/* for http://yourdomain.com/product/foo/bar
* route will result in following values:
*/
array(
"controller" => "product_foo_bar",
)
示例 #2 Yaf_Route_Mapexample
<?php
/**
* Add a map route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Map(true, "_"));
?>
以上例程的输出类似于:
/* for http://yourdomain.com/user/list/_/foo/22
* route will result in following values:
*/
array(
"action" => "user_list",
)
/**
* and request parameters:
*/
array(
"foo" => 22,
)
示例 #3 Yaf_Route_Mapexample
<?php
/**
* Add a map route to Yaf_Router route stack by calling addconfig
*/
$config = array(
"name" => array(
"type" => "map", //Yaf_Route_Map route
"controllerPrefer" => FALSE,
"delimiter" => "#!",
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
参见
- Yaf_Router::addRoute
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Rewrite
Yaf_Route_Map::route
The route purpose
说明
public bool
Yaf_Route_Map::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
简介
Yaf_Route_Regex 是Yaf内置的路由中最灵活的。
类摘要
Yaf_Route_Regex
class Yaf_Route_Regex <span class="ooclass"> extends Yaf_Route_Interface implements Yaf_Route_Interface {
/* 属性 */
protected $_route
;
protected $_default
;
protected $_maps
;
protected $_verify
;
/* 方法 */
public string
assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
public <span
class="methodname">__construct ( <span
class="methodparam">string $match
,
array
$route
[, <span
class="type">array $map
[, <span
class="methodparam">array $verify
]] )
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
/* 继承的方法 */
abstract <span
class="modifier">public string <span
class="methodname">Yaf_Route_Interface::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
abstract <span
class="modifier">public bool <span
class="methodname">Yaf_Route_Interface::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
}
属性
_route
_default
_maps
_verify
Yaf_Route_Regex::assemble
组合url
说明
public string
Yaf_Route_Regex::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
根据指定参数和自定义参数将regex这个route组合成一个url
在regex route使用assemble需要在初始化时指定reverse参数,否则将不能正常工作
参数
info
需要传入一个数组,数组的key可以为:a、:c、:m,:a表示action,:c表示controller,:m表示module。
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Regex::assembleexample
<?php
$router = new Yaf_Router();
$route = new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#",
array(
'controller' => "product", //route to product controller,
),
array(),
array(),
'/:m/:c/:a'
);
$router->addRoute("regex", $route);
var_dump($router->getRoute('regex')->assemble(
array(
':m' => 'module',
':c' => 'controller',
':a' => 'action'
),
array(
'tkey1' => 'tval1',
'tkey2' =>
'tval2'
)
)
);
以上例程的输出类似于:
string(49) "/module/controller/action?tkey1=tval1&tkey2=tval2"
返回值
Yaf_Route_Regex::__construct
The __construct purpose
说明
public <span
class="methodname">Yaf_Route_Regex::__construct ( <span
class="methodparam">string $match
,
array
$route
[, <span
class="type">array $map
[, <span
class="methodparam">array $verify
]] )
参数
match
一个完整的正则表达式,用来匹配一个请求的uri,如果不能匹配,<span
class="classname">Yaf_Route_Regex 将返回FALSE。
route
当路由正则匹配成功请求uri时,<span
class="classname">Yaf_Route_Regex将会用它来决定哪一个m/c/a被路由。
在这个数组中无论是m/c/a都是最优的,如果你没有提供一个明确的值,它将会以默认方式被路由。 另外, 你也可以使用map的结果作为m/c/a的结果.
map
将匹配到的结果捕捉放到一个已经命名好的数组中。
verify
返回值
范例
示例 #1 Yaf_Route_Regexexample
<?php
/**
* Add a regex route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)
)
);
?>
示例 #2 Yaf_Route_Regex(as of 2.3.0)example
<?php
/**
* 使用动态的controller
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Regex(
"#^/product/([^/]+)/([^/])+#", //match request uri leading "/product"
array(
'controller' => ":name", //使用上面匹配的:name, 也就是$1作为controller
),
array(
1 => "name", // now you can call $request->getParam("name")
2 => "id", // to get the first captrue in the match pattern.
)
)
);
?>
示例 #3 Yaf_Route_Regexexample
<?php
/**
* Add a regex route to Yaf_Router route stack by calling addconfig
*/
$config = array(
"name" => array(
"type" => "regex", //Yaf_Route_Regex route
"match" => "#(.*)#", //match arbitrary request uri
"route" => array(
'controller' => "product", //route to product controller,
'action' => "dummy", //route to dummy action
),
"map" => array(
1 => "uri", // now you can call $request->getParam("uri")
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
参见
- Yaf_Router::addRoute
- Yaf_Router::addConfig
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Rewrite
- Yaf_Route_Map
Yaf_Route_Regex::route
The route purpose
说明
public bool
Yaf_Route_Regex::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
路由一个传进来的请求。
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
如果正则表达式是 <span class="methodname">Yaf_Route_Regex::_construct的第一个参数,并且匹配了请求uri,返回TRUE,否则返回FALSE。
简介
类摘要
Yaf_Route_Rewrite
class Yaf_Route_Rewrite <span class="ooclass"> extends Yaf_Route_Interface implements Yaf_Route_Interface {
/* 属性 */
protected $_route
;
protected $_default
;
protected $_verify
;
/* 方法 */
public string
assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
public <span
class="methodname">__construct ( <span
class="methodparam">string $match
,
array
$route
[, <span
class="type">array $verify
] )
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
/* 继承的方法 */
abstract <span
class="modifier">public string <span
class="methodname">Yaf_Route_Interface::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
abstract <span
class="modifier">public bool <span
class="methodname">Yaf_Route_Interface::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
}
属性
_route
_default
_verify
Yaf_Route_Rewrite::assemble
组合url
说明
public string
Yaf_Route_Rewrite::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
根据指定参数和自定义参数将rewrite这个route组合成一个url
参数
info
需要传入一个数组,数组中每个key必须和初始化rewrite
route时$match参数中的带冒号的参数名一致
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Rewrite::assembleexample
router = new Yaf_Router();
$route = new Yaf_Route_Rewrite(
"/product/:name/:id/*",
array(
'controller' => "product",
),
array()
);
$router->addRoute("rewrite", $route);
var_dump($router->getRoute('rewrite')->assemble(
array(
':name' => 'foo',
':id' => 'bar',
':tmpkey1' => 'tmpval1'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
)
);
以上例程的输出类似于:
string(57) "/product/foo/bar/tmpkey1/tmpval1/?tkey1=tval1&tkey2=tval2"
返回值
Yaf_Route_Rewrite::__construct
The __construct purpose
说明
public <span
class="methodname">Yaf_Route_Rewrite::__construct ( <span
class="methodparam">string $match
,
array
$route
[, <span
class="type">array $verify
] )
参数
match
一个类似正则表达式,会被用来匹配一个请求的uri,如果匹配失败,<span
class="classname">Yaf_Route_Rewrite 会返回FALSE。
route
当路由正则匹配成功请求uri时,<span
class="classname">Yaf_Route_Rewrite
将会用它来决定哪一个m/c/a被路由。
在这个数组中无论是m/c/a都是最优的,如果你没有提供一个明确的值,它将会以默认方式被路由。
verify
返回值
范例
示例 #1 Yaf_Route_Rewriteexample
<?php
/**
* Add a rewrite route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_rewrite(
"/product/:name/:id/*", //match request uri leading "/product"
array(
'controller' => "product", //route to product controller,
),
)
);
?>
以上例程的输出类似于:
/* for http://yourdomain.com/product/foo/22/foo/bar
* route will result in following values:
*/
array(
"controller" => "product",
"module" => "index", //(default)
"action" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"name" => "foo",
"id" => 22,
"foo" => bar
)
示例 #2 Yaf_Route_Rewriteexample
<?php
/**
* Add a rewrite route to Yaf_Router route stack by calling addconfig
*/
$config = array(
"name" => array(
"type" => "rewrite", //Yaf_Route_Rewrite route
"match" => "/user-list/:id", //match only /user/list/?/
"route" => array(
'controller' => "user", //route to user controller,
'action' => "list", //route to list action
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
以上例程的输出类似于:
/* for http://yourdomain.com/user-list/22
* route will result in following values:
*/
array(
"controller" => "user",
"action" => "list",
"module" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"id" => 22,
)
示例 #3 Yaf_Route_Rewrite(as of 2.3.0)example
<?php
/**
* 使用动态结果作为action名
*/
$config = array(
"name" => array(
"type" => "rewrite", //Yaf_Route_Rewrite route
"match" => "/user-list/:a/:id", //match only /user-list/开头的
"route" => array(
'controller' => "user", //route to user controller,
'action' => ":a", //使用动态的action
),
),
);
Yaf_Dispatcher::getInstance()->getRouter()->addConfig(
new Yaf_Config_Simple($config));
?>
以上例程的输出类似于:
/* for http://yourdomain.com/user-list/list/22
* route will result in following values:
*/
array(
"controller" => "user",
"action" => "list",
"module" => "index", //(default)
)
/**
* and request parameters:
*/
array(
"id" => 22,
)
参见
- Yaf_Router::addRoute
- Yaf_Router::addConfig
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Map
Yaf_Route_Rewrite::route
The route purpose
说明
public bool
Yaf_Route_Rewrite::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
简介
<span class="classname">Yaf_Router是标准的框架路由.路由是一个拿到URI端点(URL中的URI的一部分)然后分解参数得到哪一个module, controller, 和action需要接受请求。module, controller, 和action,还有一些其他的参数是打包在一个<span class="classname">Yaf_Request_Abstract的对象中,然后通过<span class="classname">Yaf_Dispatcher来处理的。路由只发生一次:最初接到请求并且在第一个controller分发之前。 Yaf_Router 是设计来允许使用纯PHP结构的类似功能模块的跳转。它非常松散的基于Ruby on Rails的路由,并且不需要你提前就知道webserver URL跳转的相关知识。它是设计来处理一个Apache 跳转模块的规则(一个) <span class="classname">Yaf_Router是设计来允许mod_rewrite
示例 #1 Apache的跳转规则
RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css|html)$ index.php
or (preferred):
示例 #2 Apache的跳转规则
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
如果使用Lighttpd,下面的跳转规则是有效的:
示例 #3 Lighttpd的跳转规则
url.rewrite-once = (
".*\?(.*)$" => "/index.php?$1",
".*\.(js|ico|gif|jpg|png|css|html)$" => "$0",
"" => "/index.php"
)
如果使用Nginx,下面的跳转规则是有效的:
示例 #4 Nginx的跳转规则
server {
listen ****;
server_name yourdomain.com;
root document_root;
index index.php index.html;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}
默认路由
Yaf_Router预设了一个默认路由,它将以controller/action的形式匹配URIs。此外,一个module的名字可以被指定为第一路径元素,允许URIs设置为module/controller/action的形式。最后,它也会匹配一些URI中额外附加的参数,默认形式是controller/action/var1/value1/var2/value2。
Note:
Module的名字必须要定义在配置中,就application.module="Index,Foo,Bar"而言,在这种情况下,仅仅index, foo 和 bar能被考虑作为为一个module的名称。如果没有在配置文件中定义,那么Yaf使用默认的module名字“Index”。
如何匹配这些路由的一些例子:
示例 #5 Yaf_Route_Static(default route)example
// Assuming the following configure:
$conf = array(
"application" => array(
"modules" => "Index,Blog",
),
);
Controller only:
http://example/news
controller == news
Action only(when defined yaf.action_prefer=1 in php.ini)
action == news
Invalid module maps to controller name:
http://example/foo
controller == foo
Module + controller:
http://example/blog/archive
module == blog
controller == archive
Module + controller + action:
http://example/blog/archive/list
module == blog
controller == archive
action == list
Module + controller + action + params:
http://example/blog/archive/list/sort/alpha/date/desc
module == blog
controller == archive
action == list
sort == alpha
date == desc
类摘要
Yaf_Router
class Yaf_Router {
/* 属性 */
protected $_routes
;
protected $_current
;
/* 方法 */
public void
addConfig ( <span
class="methodparam">Yaf_Config_Abstract
$config
)
public <span
class="type">Yaf_Router addRoute
( string
$name
, <span
class="type">Yaf_Route_Abstract $route
)
public <span class="methodname">__construct ( <span class="methodparam">void )
public string getCurrentRoute ( <span class="methodparam">void )
public void
getRoute ( <span
class="methodparam">string $name
)
public void getRoutes ( <span class="methodparam">void )
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
}
属性
_routes
_current
Yaf_Router::addConfig
向Router中添加配置文件中定义的路由
说明
public void
Yaf_Router::addConfig ( <span
class="methodparam">Yaf_Config_Abstract
$config
)
将application.ini中定义的路由规则添加到<span class="classname">Yaf_Router的路由栈中
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
范例
示例 #1 application.iniexample
;the order is very important, the prior one will be called first
;a rewrite route match request /product/*/*
routes.route_name.type="rewrite"
routes.route_name.match="/product/:name/:value"
routes.route_name.route.controller=product
routes.route_name.route.action=info
;a regex route match request /list/*/*
routes.route_name1.type="regex"
routes.route_name1.match="#^list/([^/]*)/([^/]*)#"
routes.route_name1.route.controller=Index
routes.route_name1.route.action=action
routes.route_name1.map.1=name
routes.route_name1.map.2=value
;a simple route match /**?c=controller&a=action&m=module
routes.route_name2.type="simple"
routes.route_name2.controller=c
routes.route_name2.module=m
routes.route_name2.action=a
;a simple router match /**?r=PATH_INFO
routes.route_name3.type="supervar"
routes.route_name3.varname=r
;a map route match any request to controller
routes.route_name4.type="map"
routes.route_name4.controllerPrefer=TRUE
routes.route_namer.delimiter="#!"
示例 #2 <span class="function">Yaf_Dispatcher::autoConfigexample
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$router = $dispatcher->getRouter();
/**
* we can add some pre-defined routes in application.ini
*/
$router->addConfig(Yaf_Registry::get("config")->routes);
}
?>
参见
- Yaf_Router::addRoute
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Rewrite
- Yaf_Route_Map
Yaf_Router::addRoute
往Router中添加新的路由
说明
public <span
class="type">Yaf_Router <span
class="methodname">Yaf_Router::addRoute ( <span
class="methodparam">string $name
,
Yaf_Route_Abstract
$route
)
默认地,Yaf_Router使用<span class="classname">Yaf_Route_Static作为它的默认的路由。你可以通过调用这个方法往Router的堆栈中添加一个新的路由
在路由栈中,新的路由规则会比老的规则先调用,如果新路由规则返回TRUE,那么路由进程将会结束。否则,老的规则将会被调用。
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
范例
示例 #1 <span class="function">Yaf_Dispatcher::autoRenderexample
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$router = $dispatcher->getRouter();
/**
* we can add some pre-defined routes in application.ini
*/
$router->addConfig(Yaf_Registry::get("config")->routes);
/**
* add a Rewrite route, then for a request uri:
* http://***/product/list/22/foo
* will be matched by this route, and result:
*
* [module] =>
* [controller] => product
* [action] => info
* [method] => GET
* [params:protected] => Array
* (
* [id] => 22
* [name] => foo
* )
*
*/
$route = new Yaf_Route_Rewrite(
"/product/list/:id/:name",
array(
"controller" => "product",
"action" => "info",
)
);
$router->addRoute('dummy', $route);
}
?>
参见
- Yaf_Router::addConfig
- Yaf_Route_Static
- Yaf_Route_Supervar
- Yaf_Route_Simple
- Yaf_Route_Regex
- Yaf_Route_Rewrite
- Yaf_Route_Map
Yaf_Router::__construct
Yaf_Router constructor
说明
public <span class="methodname">Yaf_Router::__construct ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Router::getCurrentRoute
取得当前有效的路由名
说明
public string Yaf_Router::getCurrentRoute ( <span class="methodparam">void )
获取当前路由进程中正在起作用的路由名
Note:
你需要在路由进程结束之后调用此方法,在这之前,这个方法会一直返回NULL
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
String,当前起效的路由的名字
范例
示例 #1 注册一些路由到Bootstrap
<?php
class Bootstrap extends Yaf_Bootstrap_Abstract{
public function _initConfig() {
$config = Yaf_Application::app()->getConfig();
Yaf_Registry::set("config", $config);
}
public function _initRoute(Yaf_Dispatcher $dispatcher) {
$router = $dispatcher->getRouter();
$rewrite_route = new Yaf_Route_Rewrite(
"/product/list/:page",
array(
"controller" => "product",
"action" => "list",
)
);
$regex_route = new Yaf_Route_Rewrite(
"#^/product/info/(\d+)",
array(
"controller" => "product",
"action" => "info",
)
);
$router->addRoute('rewrite', $rewrite_route)->addRoute('regex', $regex_route);
}
/**
* register plugin
*/
public function __initPlugins(Yaf_Dispatcher $dispatcher) {
$dispatcher->registerPlugin(new DummyPlugin());
}
?>
示例 #2 plugin Dummy.php (under application.directory/plugins)
<?php
class DummyPlugin extends Yaf_Plugin_Abstract {
public function routerShutdown(Yaf_Request_Abstract $request, Yaf_Response_Abstract $response) {
var_dump(Yaf_Dispatcher::getInstance()->getRouter()->getCurrentRoute());
}
?>
?>
以上例程的输出类似于:
/* for http://yourdomain.com/product/list/1
* DummyPlugin will output:
*/
string(7) "rewrite"
/* for http://yourdomain.com/product/info/34
* DummyPlugin will output:
*/
string(5) "regex"
/* for other request URI
* DummyPlugin will output:
*/
string(8) "_default"
参见
- Yaf_Bootstrap_Abstract
- Yaf_Plugin_Abstract
- Yaf_Router::addRoute
Yaf_Router::getRoute
The getRoute purpose
说明
public void
Yaf_Router::getRoute ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Router::getRoutes
The getRoutes purpose
说明
public void Yaf_Router::getRoutes ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Router::route
The route purpose
说明
public bool
Yaf_Router::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
Yaf_Route_Simple 会匹配请求中的query string,然后找到路由信息。
你需要做的只是告诉 <span class="classname">Yaf_Route_Simple,在$_GET中哪个是Module,哪个是Controller,哪个是Action。
Yaf_Route_Simple::route 总是会返回TRUE,所以把<span class="classname">Yaf_Route_Simple放在路由堆栈前面是很重要的,否则其他所有的路由都可能不会被调用到。
类摘要
Yaf_Route_Simple
class Yaf_Route_Simple <span class="oointerface">implements <span class="interfacename">Yaf_Route_Interface {
/* 属性 */
protected $controller
;
protected $module
;
protected $action
;
/* 方法 */
public string
assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
public <span
class="methodname">__construct ( <span
class="methodparam">string
$module_name
, <span
class="type">string $controller_name
, <span
class="methodparam">string
$action_name
)
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
}
属性
controller
module
action
Yaf_Route_Simple::assemble
组合url
说明
public string
Yaf_Route_Simple::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
根据指定参数和自定义参数将simple这个route组合成一个url
参数
info
需要传入一个数组,数组中每个key可为:m、:c、:a,:m代表module,:c代表controller,
:a代表action
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Simple::assembleexample
<?php
$router = new Yaf_Router();
$route = new Yaf_Route_Simple('m', 'c', 'a');
$router->addRoute("simple", $route);
var_dump($router->getRoute('simple')->assemble(
array(
':a' => 'yafaction',
'tkey' => 'tval',
':c' => 'yafcontroller',
':m' => 'yafmodule'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
));
以上例程的输出类似于:
string(64) "?m=yafmodule&c=yafcontroller&a=yafaction&tkey1=tval1&tkey2=tval2"
返回值
Yaf_Route_Simple::__construct
Yaf_Route_Simple constructor
说明
public <span
class="methodname">Yaf_Route_Simple::__construct ( <span
class="methodparam">string
$module_name
, <span
class="type">string $controller_name
, <span
class="methodparam">string
$action_name
)
Yaf_Route_Simple将从query string中获得路由信息。这个构造函数的参数会被作为键到$_GET中去寻找路由信息。
Warning
本函数还未编写文档,仅有参数列表。
参数
module_name
module信息的键名。
controller_name
controller信息的键名。
action_name
action信息的键名。
返回值
总是返回TRUE
范例
示例 #1 <span class="function">Yaf_Route_Simple::routeexample
<?php
$route = new Yaf_Route_Simple("m", "controller", "act");
Yaf_Router::getInstance()->addRoute("simple", $route);
?>
示例 #2 <span class="function">Yaf_Route_Simple::routeexample
Request: http://yourdomain.com/path/?controller=a&act=b
=> module = default(index), controller = a, action = b
Request: http://yourdomain.com/path
=> module = default(index), controller = default(index), action = default(index)
参见
- Yaf_Route_Supervar::route
- Yaf_Route_Static::route
- Yaf_Route_Regex::route
- Yaf_Route_Rewrite::route
- Yaf_Route_Map::route
Yaf_Route_Simple::route
Route a request
说明
public bool
Yaf_Route_Simple::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
see Yaf_Route_Simple::__construct
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
always be TRUE
参见
- Yaf_Route_Supervar::route
- Yaf_Route_Static::route
- Yaf_Route_Regex::route
- Yaf_Route_Rewrite::route
- Yaf_Route_Map::route
简介
默认的,Yaf_Router 只有一个<span class="classname">Yaf_Route_Static 作为它默认的路由
Yaf_Route_Static 旨在处理80%的要求。
请注意:实例化 Yaf_Route_Static 是没有必要的,也没必要将它加入<span class="classname">Yaf_Router的路由堆栈,因为在<span class="classname">Yaf_Router的路由堆栈中总是存在它的一个实例,并且总是在最后被调用。
类摘要
Yaf_Route_Static
class Yaf_Route_Static <span class="oointerface">implements <span class="interfacename">Yaf_Router {
/* 方法 */
public string
assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
public void
match ( <span
class="type">string $uri
)
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
}
Yaf_Route_Static::assemble
组合url
说明
public string
Yaf_Route_Static::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
根据指定参数和自定义参数将static这个route组合成一个url
参数
info
需要传入一个数组,数组中每个key可为:m、:c、:a,:m代表module,:c代表controller,
:a代表action
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Static::assembleexample
<?php
$router = new Yaf_Router();
$route = new Yaf_Route_Static();
$router->addRoute("static", $route);
var_dump($router->getRoute('static')->assemble(
array(
':a' => 'yafaction',
'tkey' => 'tval',
':c' => 'yafcontroller',
':m' => 'yafmodule'
),
)
);
var_dump($router->getRoute('static')->assemble(
array(
':a' => 'yafaction',
'tkey' => 'tval',
':c' => 'yafcontroller',
':m' => 'yafmodule'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
)
);
以上例程的输出类似于:
string(%d) "/yafmodule/yafcontroller/yafaction"
string(%d) "/yafmodule/yafcontroller/yafaction?tkey1=tval1&tkey2=tval2"
返回值
Yaf_Route_Static::match
The match purpose
说明
public void
Yaf_Route_Static::match ( <span
class="methodparam">string $uri
)
Warning
本函数还未编写文档,仅有参数列表。
参数
uri
返回值
Yaf_Route_Static::route
Route a request
说明
public bool
Yaf_Route_Static::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
总是返回TRUE
范例
示例 #1 <span class="function">Yaf_Route_Static::routeexample
// assuming there is only one module defined:Index
Request: http://yourdomain.com/a/b
=> module = index, controller=a, action=b
//assuming ap.action_prefer = On
Request: http://yourdomain.com/b
=> module = default(index), controller = default(index), action = b
//assuming ap.action_prefer = Off
Request: http://yourdomain.com/b
=> module = default(index), controller = b, action = default(index)
Request: http://yourdomain.com/a/b/foo/bar/test/a/id/4
=> module = default(index), controller = a, action = b, request parameters: foo = bar, test = a, id = 4
参见
- Yaf_Route_Supervar::route
- Yaf_Route_Simple::route
- Yaf_Route_Regex::route
- Yaf_Route_Rewrite::route
- Yaf_Route_Map::route
简介
类摘要
Yaf_Route_Supervar
class Yaf_Route_Supervar <span class="oointerface">implements <span class="interfacename">Yaf_Route_Interface {
/* 属性 */
protected $_var_name
;
/* 方法 */
public string
assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
public <span
class="methodname">__construct ( <span
class="methodparam">string
$supervar_name
)
public bool
route ( <span
class="type">Yaf_Request_Abstract $request
)
}
属性
_var_name
Yaf_Route_Supervar::assemble
组合url
说明
public string
Yaf_Route_Supervar::assemble ( <span
class="methodparam">array $info
[,
array
$query
] )
根据指定参数和自定义参数将supervar这个route组合成一个url
参数
info
需要传入一个数组,数组中每个key可为:m、:c、:a,:m代表module,:c代表controller,
:a代表action
query
用户自定义的query string,将根据此路由规则拼接在url中
范例
示例 #1 <span class="function">Yaf_Route_Supervar::assembleexample
<?php
$router = new Yaf_Router();
$route = new Yaf_Route_Supervar('r');
$router->addRoute("supervar", $route);
var_dump($router->getRoute('supervar')->assemble(
array(
':a' => 'yafaction',
'tkey' => 'tval',
':c' => 'yafcontroller',
':m' => 'yafmodule'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2'
)
));
try {
var_dump($router->getRoute('supervar')->assemble(
array(
':a' => 'yafaction',
'tkey' => 'tval',
':m' => 'yafmodule'
),
array(
'tkey1' => 'tval1',
'tkey2' => 'tval2',
1 => array(),
)
));
} catch (Exception $e) {
var_dump($e->getMessage());
}
以上例程的输出类似于:
string(%d) "?r=/yafmodule/yafcontroller/yafaction&tkey1=tval1&tkey2=tval2"
string(%d) "You need to specify the controller by ':c'"
返回值
Yaf_Route_Supervar::__construct
The __construct purpose
说明
public <span
class="methodname">Yaf_Route_Supervar::__construct ( <span
class="methodparam">string
$supervar_name
)
Yaf_Route_Supervar 类似于 <span
class="classname">Yaf_Route_Static,不同的是<span
class="classname">Yaf_Route_Supervar 在query string
中寻找路劲信息,参数 supervar_name
是建。
Warning
本函数还未编写文档,仅有参数列表。
参数
supervar_name
键名
返回值
范例
示例 #1 Yaf_Route_Supervarexample
<?php
/**
* Add a supervar route to Yaf_Router route stack
*/
Yaf_Dispatcher::getInstance()->getRouter()->addRoute("name",
new Yaf_Route_Supervar("r"));
);
?>
以上例程的输出类似于:
/** for request: http://yourdomain.com/xx/oo/?r=/ctr/act/var/value
* will result in following:
*/
array (
"module" => index(default),
"controller" => ctr,
"action" => act,
"params" => array(
"var" => value,
)
)
参见
- Yaf_Router::addRoute
- Yaf_Router::addConfig
- Yaf_Route_Static
- Yaf_Route_Regex
- Yaf_Route_Simple
- Yaf_Route_Rewrite
- Yaf_Route_Map
Yaf_Route_Supervar::route
The route purpose
说明
public bool
Yaf_Route_Supervar::route ( <span
class="methodparam">Yaf_Request_Abstract
$request
)
Warning
本函数还未编写文档,仅有参数列表。
参数
request
返回值
如果在$_GET中有键(在 <span class="methodname">Yaf_Route_Supervar::__construct中定义),返回TRUE,否则返回FALSE。
简介
类摘要
Yaf_Session
class Yaf_Session <span class="oointerface">implements <span class="interfacename">Iterator <span class="oointerface">, Traversable , <span class="interfacename">ArrayAccess <span class="oointerface">, Countable {
/* 属性 */
protected <span
class="modifier">static $_instance
;
protected $_session
;
protected $_started
;
/* 方法 */
__construct ( <span class="methodparam">void )
public void count ( <span class="methodparam">void )
public void current ( <span class="methodparam">void )
public void
del ( <span
class="type">string $name
)
public void
__get ( <span
class="methodparam">string $name
)
public <span class="modifier">static void <span class="methodname">getInstance ( <span class="methodparam">void )
public void
has ( <span
class="type">string $name
)
public void
__isset ( <span
class="methodparam">string $name
)
public void key ( <span class="methodparam">void )
public void next ( <span class="methodparam">void )
public void
offsetExists ( <span
class="methodparam">string $name
)
public void
offsetGet ( <span
class="methodparam">string $name
)
public void
offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
public void
offsetUnset ( <span
class="methodparam">string $name
)
public void rewind ( <span class="methodparam">void )
public void
__set ( <span
class="methodparam">string $name
,
string
$value
)
public void start ( <span class="methodparam">void )
public void
__unset ( <span
class="methodparam">string $name
)
public void valid ( <span class="methodparam">void )
}
属性
_instance
_session
_started
Yaf_Session::__construct
The __construct purpose
说明
Yaf_Session::__construct ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::count
The count purpose
说明
public void Yaf_Session::count ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::current
The current purpose
说明
public void Yaf_Session::current ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::del
The del purpose
说明
public void
Yaf_Session::del ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::__get
The __get purpose
说明
public void
Yaf_Session::__get ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::getInstance
The getInstance purpose
说明
public <span class="modifier">static void <span class="methodname">Yaf_Session::getInstance ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::has
The has purpose
说明
public void
Yaf_Session::has ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::__isset
The __isset purpose
说明
public void
Yaf_Session::__isset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::key
The key purpose
说明
public void Yaf_Session::key ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::next
The next purpose
说明
public void Yaf_Session::next ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::offsetExists
The offsetExists purpose
说明
public void
Yaf_Session::offsetExists ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::offsetGet
The offsetGet purpose
说明
public void
Yaf_Session::offsetGet ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::offsetSet
The offsetSet purpose
说明
public void
Yaf_Session::offsetSet ( <span
class="methodparam">string $name
,
string
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Session::offsetUnset
The offsetUnset purpose
说明
public void
Yaf_Session::offsetUnset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::rewind
The rewind purpose
说明
public void Yaf_Session::rewind ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::__set
The __set purpose
说明
public void
Yaf_Session::__set ( <span
class="methodparam">string $name
,
string
$value
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
value
返回值
Yaf_Session::start
The start purpose
说明
public void Yaf_Session::start ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Session::__unset
The __unset purpose
说明
public void
Yaf_Session::__unset ( <span
class="methodparam">string $name
)
Warning
本函数还未编写文档,仅有参数列表。
参数
name
返回值
Yaf_Session::valid
The valid purpose
说明
public void Yaf_Session::valid ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
类摘要
Yaf_Exception
class Yaf_Exception <span class="ooclass"> extends Exception {
/* 属性 */
protected $message
;
protected $code
;
protected $previous
;
/* 方法 */
public <span class="methodname">__construct ( <span class="methodparam">void )
public void getPrevious ( <span class="methodparam">void )
/* 继承的方法 */
final public string <span class="methodname">Exception::getMessage ( <span class="methodparam">void )
final public Throwable <span class="methodname">Exception::getPrevious ( <span class="methodparam">void )
final public mixed <span class="methodname">Exception::getCode ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getFile ( <span class="methodparam">void )
final public int <span class="methodname">Exception::getLine ( <span class="methodparam">void )
final public array <span class="methodname">Exception::getTrace ( <span class="methodparam">void )
final public string <span class="methodname">Exception::getTraceAsString ( <span class="methodparam">void )
public string Exception::__toString ( <span class="methodparam">void )
final <span class="modifier">private void <span class="methodname">Exception::__clone ( <span class="methodparam">void )
}
属性
message
code
file
line
previous
Yaf_Exception::__construct
The __construct purpose
说明
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
Yaf_Exception::getPrevious
The getPrevious purpose
说明
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
Warning
本函数还未编写文档,仅有参数列表。
参数
此函数没有参数。
返回值
简介
类摘要
Yaf_Exception_TypeError
class Yaf_Exception_TypeError <span class="ooclass"> extends Yaf_Exception {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_StartupError
class Yaf_Exception_StartupError extends Yaf_Exception {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_DispatchFailed
class Yaf_Exception_DispatchFailed extends Yaf_Exception {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_RouterFailed
class Yaf_Exception_RouterFailed extends Yaf_Exception {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_LoadFailed
class Yaf_Exception_LoadFailed extends Yaf_Exception {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_LoadFailed_Module
class Yaf_Exception_LoadFailed_Module extends Yaf_Exception_LoadFailed {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_LoadFailed_Controller
class Yaf_Exception_LoadFailed_Controller extends Yaf_Exception_LoadFailed {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_LoadFailed_Action
class Yaf_Exception_LoadFailed_Action extends Yaf_Exception_LoadFailed {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}
简介
类摘要
Yaf_Exception_LoadFailed_View
class Yaf_Exception_LoadFailed_View extends Yaf_Exception_LoadFailed {
/* 属性 */
/* 方法 */
/* 继承的方法 */
public <span class="methodname">Yaf_Exception::__construct ( <span class="methodparam">void )
public void Yaf_Exception::getPrevious ( <span class="methodparam">void )
}