我用它来查询不在:
$usertypes=Usertype::find()->where(['not in ','user_type_id',['2,3,4']])->all();
Run Code Online (Sandbox Code Playgroud)
错误:
Database Exception – yii\db\Exception
Run Code Online (Sandbox Code Playgroud)
未定义的偏移量:1无法准备SQL:SELECT*FROM usertypeWHERE user_type_idNOT IN:qp0
还尝试了数组格式为['2','3','4']但不起作用?问题是什么?
在我的控制器中
`namespace app\api\modules\v1\controllers;
namespace app\api\modules\v1\controllers;
use yii\rest\ActiveController;
use yii\filters\VerbFilter;
use yii\web\Response;
class CountryController extends ActiveController
{
public $modelClass = 'app\models\Country';
public function behaviors()
{
return [
[
'class' => 'yii\filters\ContentNegotiator',
'only' => ['index', 'view','create','update','search'],
'formats' => ['application/json' =>Response::FORMAT_JSON,],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index'=>['get'],
'view'=>['get'],
'create'=>['post'],
'update'=>['PUT'],
'delete' => ['delete'],
'deleteall'=>['post'],
'search' => ['get']
],
]
];
}
}`
Run Code Online (Sandbox Code Playgroud)
我试试我的POSTMAN应用程序
对于创建我使用POST 的http://本地主机/ MYAPP/API/V1 /国家工程fine.But对于更新我使用PUT HTTP://本地主机/ MYAPP/API/V1 /国家/ 16返回16的纪录JSON输出没有按预期更新.
哪里错了?谢谢!!
为了设置错误操作,我在控制器中添加了此代码
public function beforeAction($action) {
if ($action->id == 'error')
$this->layout = 'iframe-main.php';
$this->enableCsrfValidation = false;
return parent::beforeAction($action);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用。错误布局显示在默认布局中
我的控制器文件在 api/v1/controller/
class ProfileController extends ActiveController
{
public $modelClass = 'app\models\Profile';
public function behaviors()
{
return [
[
'class' => 'yii\filters\ContentNegotiator',
'only' =>
['index', 'view', 'createnew','update','search'],
'formats' =>
['application/json' => Response::FORMAT_JSON,],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'index' => ['get'],
'view' => ['get'],
'createnew' => ['post'],
'update' => ['put'],
'delete' => ['delete'],
'deleteall' => ['post'],
'search' => ['get']
],
]
];
}
public function actionCreatenew() {
$model = new Profile();
$model->load(Yii::$app->request->post());
$model->asset = UploadedFile::getInstance($model, 'asset');
$name …Run Code Online (Sandbox Code Playgroud)