gpt4 book ai didi

php - Yii Framework 2.0 -findModel 返回一个空对象

转载 作者:行者123 更新时间:2023-11-29 14:17:34 24 4
gpt4 key购买 nike

我正在尝试显示我存储在数据库中的表单值。但它没有发生并且还返回空值。我已经添加了我所做的一切。

Controller

protected function findModel($id)
{
if (($model = UserRegistration::find($id)->one()) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}

型号

这是我的模型。我已将所有变量声明为公共(public)变量。这有问题吗?如果我删除我也会收到错误消息。

class UserRegistration extends ActiveRecord
{
public $username;
public $firstname;
public $lastname;
public $email;
public $Country;
public $State;
public $City;
public $phone_number;
public $about_me;
public $password;
public $verify_password;
public $photo;

public static function tableName()
{
return 'user';
}

public function rules()
{
return [
[['username','password', 'email'], 'required'],
[['status', 'created_at', 'updated_at', 'teespring_id'], 'integer'],
[['username','lastname','firstname', 'password_hash', 'password_reset_token', 'email','about_me'], 'string', 'max' => 255],
[['auth_key'], 'string', 'max' => 32],
[['role'], 'string', 'max' => 10],
[['email','username'],'email'],
[['email','username','password_reset_token'], 'unique'],
['phone_number','string','length'=>10],
[['Country','State','City'],'string'],
['verify_password','compare','compareAttribute'=>'password'],
[['photo'],'file', 'extensions' => 'png, jpg']
];
}
}

更新:我也尝试过 $model = UserRegistration::findOne($id)。但运气不好请帮助我。

最佳答案

它是 UserRegistration::findOne($id) 并且您不能声明来自数据库的属性,因为它们将为空。

关于php - Yii Framework 2.0 -findModel 返回一个空对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43138535/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com