Yii 1.1 请求报400错误

Yii的action可以带参数,比如:

1 class PostController extends CController
2 {
3     public function actionCreate($category, $language='en')
4     {
5         $category=(int)$category;
6 
7         // ... fun code starts here ...
8     }
9 }

这样确实很方便。不过,这默认只从$_GET中提取参数的。如果是post请求,就会报400错误。

如果想使用其他类型的请求参数,可以重写CController的getActionParams()方法:

/**
 * Returns the request parameters that will be used for action parameter binding.
 * By default, this method will return $_GET. You may override this method if you
 * want to use other request parameters (e.g. $_GET+$_POST).
 * @return array the request parameters to be used for action parameter binding
 * @since 1.1.7
 */
public function getActionParams()
{
    return $_GET;
}
原文地址:https://www.cnblogs.com/royhoo/p/5508823.html