-2
我在我的視圖文件夾(menu.php)中有一個導航欄菜單我在我的供應商視圖(supplier.php)中被稱爲此菜單,因爲我需要high-lite選定的菜單項。Yii2頁面渲染功能禁用表單字段
代碼在supplier.php
<?= $this->render('menu', ['currentpage'=>'Suppliers']); ?>
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
?>
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Type')->dropDownList([ 'Individual' => 'Individual', 'Registered' => 'Registered', ], ['prompt' => '']) ?>
<?= $form->field($model, 'Licence_no')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Estate')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Acreage')->textInput() ?>
<?= $form->field($model, 'NIC')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'Tel')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
menu.php編碼(參照 '有效'=>($當前頁== '商'))
<?php
use kartik\sidenav\SideNav;
?>
<div class="row">
<div class="col-xs-5 col-sm-4 col-lg-3">
<?= SideNav::widget([
'type' => SideNav::TYPE_DEFAULT,
'heading' => 'System Functions',
'items' => [
[
'url' => '../dashboard/manager',
'label' => Yii::t('app','Dashboard'),
'icon' => 'home',
'active' => ($currentpage == 'Manager')
],
[
'url' => '#',
'label' => 'Purchase',
'icon' => 'home',
'items' => [
[
'url' => '../dashboard/suppliers',
'label' => Yii::t('app','Suppliers'),
'icon'=>'glyphicon transport',
'active' => ($currentpage == 'Suppliers')
],
[
'url' => '../dashboard/leaf-entry',
'label' => 'Leaf Collection',
'icon'=>'leaf',
'active' => ($currentpage == 'Leaf')
],
[
'url' => '../dashboard/payments',
'label' => 'Payments',
'icon'=>'phone',
'active'=> ($currentpage == 'Payments')
],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
[
'label' => 'Stock',
'icon' => 'question-sign',
'items' => [
['label' => 'Live Stock', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Auction Despatch', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Production Tracker', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
[
'label' => 'Human Resource',
'icon' => 'question-sign',
'items' => [
['label' => 'Employees', 'icon'=>'info-sign', 'url'=>'#'],
['label' => 'Time Tracker', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Payments', 'icon'=>'phone', 'url'=>'#'],
['label' => 'Reports', 'icon'=>'phone', 'url'=>'#']
],
],
],
]);
?>
</div>
</div>
控制器功能
public function actionSuppliers()
{
$this->layout = 'DashboardLayout';
$model = new LeafSupplier();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
//return $this->redirect(['view', 'id' => $model->Supplier_id]);
} else {
return $this->render('suppliers',[
'model' => $model,
],
[ 'currentpage' => 'Suppliers']);
}
}
突出顯示 '供應商' 菜單項
所有這些修改後形成字段不能編輯。無法輸入任何被禁用的值。一旦我註釋掉這個render('menu',['currentpage'=>'Suppliers']); ?>表單字段可以編輯。
在supplier.php
註釋代碼註釋後的渲染方法字段是可編輯的。
沒有足夠的信息...該部分菜單沒有任何問題。問題在別處。 – Clyff
你錯了。你可以在我的supplier.php文件中看到代碼'render('menu',['currentpage'=>''''))''。當我從頁面發表評論時,我可以在表單中輸入值。否則不能 –
再一次,菜單的該部分沒有任何問題。問題在別處。這個項目由它自己不會導致問題。你在menu.php的另一部分中犯了錯誤。仍然沒有足夠的信息。 – Clyff