原文地址:http://php8848.com/3447.htmlphp
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()的关系 , 目前来看是相同的html
5. forward 和render的关系
render是视图渲染函数,调用该函数能够返回选而后的字符串,并且,assign的值在同一次的请求中会共用。
$this->forward($action, array(“name” => $value)); 是一个跳转函数,可是并不会立刻跳转,而是会等到action结束以后在跳转。第一个参数是一个action名称,第二个参数是传递的参数。web
6. forward到其余的controller的action应该怎么写ajax
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请求,就会直接夸张跳转。post