public function init() { //code }
get接值:php
$this->getRequest()->get("user")
post接值:html
$this->getRequest()->getPost("user")
post请求方式判断:ajax
$this->getRequest()->isPost()
判断ajax请求session
/** * 若是是Ajax请求, 则关闭HTML输出 * disableView() 关闭HTML输出 * enableView() 开启HTML输出 */ if ($this->getRequest()->isXmlHttpRequest()) { Yaf_Dispatcher::getInstance()->disableView(); }
3、dom
导入一个PHP文件, 由于Yaf_Loader::import只是专一于一次包含, 因此要比传统的require_once性能好一些函数
<?php //绝对路径 Yaf_Loader::import("/usr/local/foo.php); //相对路径, 会在APPLICATION_PATH."/library"下加载 Yaf_loader::import("plugins/User.php"); ?>
载入一个类, 这个方法被Yaf用做自动加载类的方法, 固然也能够手动调用.post
<?php Yaf_Loader::autoload("Baidu_ST_Dummy_Bar"); ?>
<?php class IndexController extends Yaf_Controller_Abstract { public function init() { if ($this->getRequest()->isXmlHttpRequest()) { //若是是Ajax请求, 关闭自动渲染, 由咱们手工返回Json响应 Yaf_Dispatcher::getInstance()->autoRender(FALSE); } } } ?>
设置错误处理函数 Yaf_Dispatcher::setErrorHandler
性能
获取当前的请求实例 Yaf_Dispatcher::getRequest( void );
ui
设置路由的默认控制器 Yaf_Dispatcher::setDefaultController
( string $default_controller_name );
this
设置路由的默认模块 Yaf_Dispatcher::setDefaultModule( string $default_module_name );
设置路由的默认动做 Yaf_Dispatcher::setDefaultAction( string $default_module_name );
切换在Yaf出错的时候抛出异常, 仍是触发错误. Yaf_Dispatcher::throwException( boolean $switch );
是否启用默认捕获异常机制 Yaf_Dispatcher::catchException( boolean $switch );
设置session: Yaf_Session::getInstance()->set("admin_username",$username);
读取session: Yaf_Session::getInstance()->get("admin_username") ;
销毁session: Yaf_Session::getInstance()->del("admin_username");
跳转: $this->forwaard('login');
重定向到新的路径 $this->redirect('/login/');
重定向请求到新的路径 $this->getResponse()->setRedirect("http://domain.com/");
获取当前请求类型 $this->getRequest()->getMethod()