public function up() { $this->execute('ALTER TABLE galaxysss_1.gs_services ADD column_name int NULL;'); $rows = \app\models\Service::query()->select(['id', 'date_insert'])->all(); foreach ($rows as $row) { $date = new DateTime($row['date_insert']); \app\models\Service::find($row['id'])->update(['column_name' => $date->format('U')]); } // удаляю старую колонку $this->execute('ALTER TABLE galaxysss_1.gs_services DROP date_insert;'); // переименовываю вновь созданную колонку $this->execute('ALTER TABLE galaxysss_1.gs_services CHANGE column_name date_insert int NULL;'); }
public function actionServices() { return $this->render(['list' => Service::query()->select(['id', 'header', 'description', 'if(length(ifnull(content, "")) > 0, 1, 0) as is_content', 'image', 'link', 'date_insert'])->all()]); }
public function actionIndex() { return $this->render(['items' => \app\models\Service::query()->orderBy(['date_insert' => SORT_DESC])->all()]); }