public static function getParents($id, $fromCache = true) { $ret = []; $current = Dict::findOne(['id' => $id]); if ($current === null) { return $ret; } array_unshift($ret, $current); $parent = Dict::findOne(['id' => $current['parent_id']]); while ($parent != null) { array_unshift($ret, $parent); $parent = Dict::findOne(['id' => $parent['parent_id']]); } return $ret; }
/** * Finds the Dict model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Dict the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { $id = intval($id); if ($id === 0) { $model = new Dict(); $model->id = 0; $model->name = '根字典'; return $model; } if (($model = Dict::findOne($id)) !== null) { return $model; } else { //throw new NotFoundHttpException('The requested page does not exist.'); } }