T
T
Theory Theory2020-09-02 17:45:42
Yii
Theory Theory, 2020-09-02 17:45:42

Why is only id filled in?

There are 2 fields in the database - id (AUTO_INCREMENT) and title

Model:

namespace app\models;
use yii\db\ActiveRecord;

class First extends ActiveRecord
{
  public $title;
  
  public static function tableName ()
  {
    return '{{news}}';
  }

  public function rules()
    {
        return [
            [['title'], 'string'],
        ];
    }
}


Controller:
$model = new News();
    $model->title = "wow";
    $model->save();


As a result, the query is executed - INSERT INTO `news` (`id`) VALUES (DEFAULT)
Where is title ?

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
M
Maxim, 2020-09-02
@Narbek

public $titletake away

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question