<div class="col-xs-4"> <?php // Obtener el id_ente del usuario conectado $entes = Yii::$app->user->identity->id_ente; // Verificar si el usuario es administrador if ((Userbackend::isUserAdmin(Yii::$app->user->identity->username)) || (Userbackend::isUserDesp_Ministro(Yii::$app->user->identity->username))) { // Si el usuario es administrador, mostrar todas las opciones echo $form->field($model, 'id_ente')->dropDownList( ArrayHelper::map(Entes::find()->where(['id_sector' => 2])->orderBy('nombre_ente')->all(), 'id_ente', 'nombre_ente'), ['prompt' => 'Seleccione ', 'id' => 'id-ente'] ); } else { // Si el usuario no es administrador, mostrar solo el id_ente del usuario conectado echo $form->field($model, 'id_ente')->dropDownList( ArrayHelper::map(Entes::find()->where(['id_ente' => $entes])->orderBy('nombre_ente')->all(), 'id_ente', 'nombre_ente'), ['prompt' => 'Seleccione ', 'id' => 'id-ente'] ); } ?> </div> //otro ejemplo mas complejo <div class="row"> <div class="col-xs-3"> <?php // Obtener el id_ente del usuario conectado $entes = Yii::$app->user->identity->id_ente; // Verificar si el usuario es administrador if ((Userbackend::isUserAdmin(Yii::$app->user->identity->username)) || (Userbackend::isUserDesp_Ministro(Yii::$app->user->identity->username))) { // Si el usuario es administrador, mostrar todas las opciones echo $form->field($model, 'id_ente')->dropDownList( ArrayHelper::map(Entes::find()->where(['id_sector' => 2])->orderBy('nombre_ente')->all(), 'id_ente', 'nombre_ente'), ['prompt' => 'Seleccione ', 'id' => 'id-ente'] ); } else { $entemus = Entes::getEntenom1($entes); // Si el usuario no es administrador, mostrar solo el id_ente del usuario conectado echo $form->field($model, 'entemus')->textInput(['value' => $entemus, 'readonly' => true]); echo $form->field($model, 'id_ente')->hiddenInput(['value' => $entes, 'readonly' => true/*, 'id' => 'id-ente'*/])->label(false); } ?> </div> <div class="col-xs-3"> <?php if ((Userbackend::isUserAdmin(Yii::$app->user->identity->username)) || (Userbackend::isUserDesp_Ministro(Yii::$app->user->identity->username))) { // Si el usuario es administrador, mostrar todas las opciones ?> <?= $form->field($model, 'id_indicador')->widget(DepDrop::classname(), [ 'options' => ['id' => 'id-indicador', 'onchange' => 'buscarEnte(this.value)'], 'data' => [$model->id_indicador => $model->Indicadores], // ensure at least the preselected value is available 'pluginOptions' => [ 'depends' => ['id-ente'], // the id for cat attribute 'placeholder' => 'Seleccione un indicador...', 'url' => Url::to(['indicadores/listar']) ] ]); } else { ?> <?= $form->field($model, 'id_indicador')->dropDownList( ArrayHelper::map(Indicadoresentescon::find()->where(['id_ente'=>$entes])->andWhere(['id_identificador' => 1])->andWhere(['id_sector' => 2])->orderBy('nombre_indicador')->all(), 'id_indicador', 'nombre_indicador'), ['prompt' => 'Seleccione ', 'onchange' => 'buscarEnte(this.value)'] ); } ?> </div> <div class="col-xs-3"> <?= $form->field($model, 'fecha')->widget( DatePicker::classname(), [ 'language' => 'es', 'removeButton' => false, 'options' => [ 'placeholder' => 'Fecha:', 'class' => 'form-control', 'id' => 'fecha_desde-input', 'onchange' => 'buscarProyeccion(this.value)' ], 'pluginOptions' => [ 'startDate' => '01-01-2000', //'startDate' => date('d-m-Y'), 'autoclose' => true, 'format' => 'dd-mm-yyyy', ] ] )->label('Fecha'); ?> </div> </div>
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter