yaf框架的一些函数

来源:互联网 发布:csgo网络不稳定 编辑:程序博客网 时间:2024/06/06 02:46

原文地址:http://php8848.com/3447.html

controller层的知识
1.  $this->getView  取得与action同名的view
2.  在action中关闭模版输出
Yaf_Dispatcher::getInstance()->autoRender(FALSE); 或者 Yaf_Dispatcher :: getInstance() -> disableView();
3.  如果action过于复杂,可以通过  actions数组来定义一个继承actions基类的类去单独创建一个文件来完成逻辑, 实现方法,只要在actons属性中定义一个数组  array(‘action’=>’action/inex.php’);  这样就能调用,而把逻辑放在 execute里面。
4.  搞清楚view层的方法,  assign()和  assignRef()的关系  , 目前来看是相同的

5. forward 和render的关系
render是视图渲染函数,调用该函数可以返回选然后的字符串,而且,assign的值在同一次的请求中会共用。
$this->forward($action, array(“name” => $value)); 是一个跳转函数,但是并不会马上跳转,而是会等到action结束之后在跳转。第一个参数是一个action名称,第二个参数是传递的参数。

6.  forward到其他的controller的action应该怎么写

7. action如何区分是 post 还是get请求,还是 ajax请求
可以用
$this->getRequest()->isGet()
$this->getRequest()->isPost()
$this->getRequest()->isXmlHttpRequest()
来判定是get还是post还是ajax请求

8. forward 函数是一个有几种方式,最后一个参数必须是数组
public boolean Yaf_Controller_Abstract::forward( string  $action , array  $params = NULL );
public boolean Yaf_Controller_Abstract::forward( string  $controller , string  $action , array  $params = NULL );
public boolean Yaf_Controller_Abstract::forward( string  $module , string  $controller , string  $action , array  $params = NULL );

9. redirect 函数的用法
$this->redirect(“/login/”);   可以写全路径也可以写相对路径,区别在于在最前面是否有反斜杠。 也可以写http请求,就会直接夸张跳转。

原创粉丝点击