yii2在$model->;之后未获取id;save()并单击“更新项目”图标时

yii2在$model->;之后未获取id;save()并单击“更新项目”图标时,yii2,Yii2,我有一个yii2项目,我在我的windows本地主机上开发,并在linux上远程托管。 本地(windows)一切都很完美。 在linux上,$nodel->save()之后有$model->id=null,尽管数据已保存 public function actionCreate() { $model = new AppBreakingNews(); if ($model->load(Yii::$app->request->post()) &

我有一个yii2项目,我在我的windows本地主机上开发,并在linux上远程托管。 本地(windows)一切都很完美。 在linux上,$nodel->save()之后有$model->id=null,尽管数据已保存

 public function actionCreate() {
        $model = new AppBreakingNews();

        if ($model->load(Yii::$app->request->post()) && $model->save()) {
            return $this->redirect(['view', 'id' => $model->id]);
        } else {
            return $this->render('create', [
                        'model' => $model,
            ]);
        }
    }
我已经试过了($model->id)在保存后,它打印为空

此外,当我在网格视图中单击更新图标时,我也面临同样的问题

AppBreakingNews如下:

<?php

namespace app\models\appmodels;

use app\models\BreakingNews;
use yii\behaviors\TimestampBehavior;


class AppBreakingNews extends BreakingNews {

    public function behaviors() {
        return [
            [
                'class' => TimestampBehavior::className(),
                'createdAtAttribute' => 'created_at',
                'updatedAtAttribute' => 'updated_at',
                'value' => date('Y-m-d H:i:s'),
            ],
        ];
    }

}

请尝试保存模型->保存(false);因为我认为它验证了模型文件中的某些内容

public function actionCreate() {
    $model = new AppBreakingNews();

    if ($model->load(Yii::$app->request->post()) && $model->save(false)) {
        return $this->redirect(['view', 'id' => $model->id]);
    } else {
        return $this->render('create', [
                    'model' => $model,
        ]);
    }
}

或者请在此处打印您的模型文件。

检查托管服务器中的数据库,确保您的
id
列具有
AUTO_INCREMENT
请使用model AppBreakingNews更新您的问题。php如果托管服务器id是AUTO incrementedIs
id
表的主键,请参阅。此模型中没有编写任何规则。而且,这个模型是对BreakingNews.php模型的扩展。因此,请使用此模型更新您的问题。我的模型是AppBreakingNews,可与问题一起使用。谢谢你的回复,我将测试这个建议。但是如果它有效,我仍然需要验证如果我的答案有用,请用绿色勾号标记它对将来的用户参考有用@GaliloGaliloDear Arshad,抱歉,答案没有用处,因为问题与验证无关,它与数据库有关。我可以说谢谢你。如果你看到我不明白你的想法,请告诉我一些证据。。。