Yii Framework Forum: 关于YII2 rest风格编程的2个问题 - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

关于YII2 rest风格编程的2个问题 Rate Topic: -----

#1 User is offline   Mr.S 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 23-October 14

Posted 15 April 2015 - 03:07 AM

1.index操作的根据条件查找问题
目前我都是把过滤条件写在URL里,如: xxx.com/user?name=jack&age=30, 在Controller里自定义prepareDataProvider,最后在自己写的函数里通过Yii::$app->request->queryParams拿到过滤条件,然后拼成一个activeQuery放进acitveDataProvider返回.一切过程都是手写,请问YII2是否已经实现了默认的操作方法?

2.create,update,delete的自定义操作可否写进Controller里
目前只有index和view两种GET操作的自定义方法可以写进Controller.想要自定义以上三种操作,我现在的做法是重写action()函数,指定父类actions数组的对应操作的class,如:
function actions(){
    $actions = parent::actions();
    $actions['create']['class'] = 'app\my_action_path\MyCreateAction';
    return $actions;
}

但是我没找到在controller中直接自定义create,update,delete这三种操作的方法.请问YII2有没有提供直接在controller中自定义以上三种操作的方法,每种操作都要创建文件真的很累诶...
0

#2 User is offline   hehbhehb 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 54
  • Joined: 24-February 12

Posted 03 October 2017 - 03:30 AM

unset(actions['create'])
然后提供一个actionCreate()函数就可以,不用新增文件的
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users