/** * @param Pages|null $model * @return Pages */ public static function getRoot(Pages $model = null) { if (is_null($model)) { $model = new self(); } $root = $model->roots()->find(); if (!$root) { $model->title = '/'; $model->url = 'mainPageRootTree'; $model->level = 1; $model->parent_id = 0; $model->status = 1; $model->type_module = 0; $model->saveNode(); $root = $model->roots()->find(); } return $root; }