/** * Finds the Nav model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Nav the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Nav::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
use yii\bootstrap\ActiveForm; use yii\helpers\ArrayHelper; use common\helpers\General; use common\models\extend\Nav; use kartik\file\FileInput; use yii\helpers\Url; /* @var $this yii\web\View */ /* @var $model common\models\extend\Nav */ /* @var $form yii\widgets\ActiveForm */ if ($model->isNewRecord) { $model->status = true; $model->order = 10; $model->link_url = 'http://turen.pw?r='; $model->re_link_url = 'http://turen.pw?r='; } $parentIds = ArrayHelper::merge(['0' => Yii::t('extend', 'Top Nav')], ArrayHelper::map(General::recursiveObj(Nav::find()->orderBy(['order' => SORT_ASC])->all()), 'id', 'name')); $target = ['_blank' => Yii::t('extend', 'Blank'), '_parent' => Yii::t('extend', 'Parent'), '_self' => Yii::t('extend', 'Self')]; ?> <div class="row nav-form"> <div class="col-md-12"> <?php $form = ActiveForm::begin(['layout' => 'horizontal', 'fieldConfig' => ['template' => "{label} {beginWrapper} {input} {hint} {error} {endWrapper}", 'horizontalCssClasses' => ['label' => 'col-sm-2', 'offset' => 'col-sm-offset-2', 'wrapper' => 'col-sm-8', 'error' => '', 'hint' => '']]]); ?> <?php echo $form->field($model, 'parent_id')->dropDownList($parentIds); ?> <?php echo $form->field($model, 'name')->hint('<i class="fa fa-info-circle"></i> ' . Yii::t('extend', 'Through the title calls this menu'))->textInput(['maxlength' => true]);
/** * 返回指定标记的子菜单 * @param string $name * @return multitype:array */ public function TgetNav($name) { $model = Nav::find()->where(['name' => $name])->active()->one(); if ($model) { return $this->recursive(Nav::find()->active()->orderBy('order ASC')->all(), $model->id); } else { throw new ErrorException('Not found menu:' . $name); } }