小编Jac*_*had的帖子

Yii2 NOT IN条件不起作用

我用它来查询不在:

 $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']但不起作用?问题是什么?

mysql activerecord yii2 yii2-active-records

10
推荐指数
2
解决办法
2万
查看次数

Yii2 Rest API PUT方法不起作用

在我的控制器中

`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输出没有按预期更新.

哪里错了?谢谢!!

rest yii2

7
推荐指数
2
解决办法
2170
查看次数

在 yii2 中设置错误动作布局不起作用

为了设置错误操作,我在控制器中添加了此代码

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)

但它不起作用。错误布局显示在默认布局中

error-handling yii2 yii2-basic-app

3
推荐指数
1
解决办法
6826
查看次数

Rest API yii2中的文件上传

我的控制器文件在 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)

rest yii2

2
推荐指数
1
解决办法
9408
查看次数