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;
}

 

相关文章:

  • 2021-08-07
  • 2021-11-30
  • 2021-12-13
  • 2021-09-17
  • 2021-08-07
  • 2021-08-04
  • 2021-06-16
  • 2021-06-14
猜你喜欢
  • 2021-12-14
  • 2021-11-08
  • 2021-08-07
  • 2021-08-07
  • 2021-05-05
  • 2021-11-27
  • 2021-08-07
相关资源
相似解决方案