I'm starting with Yii2 and want to save something to my database. this is my model:
class Course extends ActiveRecord
{
public $name;
public function rules()
{
return [
[['name'], 'integer']
];
}
}
and I call it like this:
$Course = new Course();
$Course->name = 44;
$Course->save();
This is a simple code but it insert null in my database. my table just has a name column as int. What is the solution? I have read THIS question but his problem is not the same as me
If name
is the real column name from your database you need to remove
public $name;
from your ActiveRecord class. You can not have model properties of the same name as the database columns declared in the class because ActiveRecord won't work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With