Answer the question
In order to leave comments, you need to log in
YII: What are the reasons why Model->Save() may not be saved to the database?
Model:
namespace common\models;
use Yii;
use yii\base\Model;
class Messages extends \yii\db\ActiveRecord
{
public $message;
public $subject;
public $creation_date;
public $update_date;
public $status;
public $user_id;
public $parent_id;
public function rules()
{
return [
'blank' => [
['subject', 'message'],
'required',
'message' => 'This field can not be blank',
]
];
}
public function saveDialog() {
if ($this->validate()) {
$dialog = new Messages();
//$dialog = Messages::findOne(1);
$dialog->message = '111';
$dialog->subject = "1222";
var_dump($dialog);
return $dialog->save();
} else {
return false;
}
}
}
object(common\models\Messages)#113 (15) {
["message"]=
string(3) "test"
["subject"]=
string(4) "test"
["creation_date"]=
NULL
["update_date"]=
NULL
["status"]=
NULL
["user_id"]=
NULL
["parent_id"]=
NULL
["_attributes":"yii\db\BaseActiveRecord":private]=
array(0) {
}
["_oldAttributes":"yii\db\BaseActiveRecord":private]=
NULL
["_related":"yii\db\BaseActiveRecord":private]=
array(0) {
}
["_errors":"yii\base\Model":private]=
NULL
["_validators":"yii\base\Model":private]=
NULL
["_scenario":"yii\base\Model":private]=
string(7) "default"
["_events":"yii\base\Component":private]=
array(0) {
}
["_behaviors":"yii\base\Component":private]=
array(0) {
}
}
Answer the question
In order to leave comments, you need to log in
delete it
public $message;
public $subject;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question