Yii2页面渲染功能禁用表单字段

时间:2016-01-18 04:46:20

标签: yii2 yii2-basic-app

我的视图文件夹(menu.php)中有一个导航栏菜单我在供应商视图(supplier.php)中调用了这个菜单,因为我需要高亮显示所选的菜单项。

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编码(请参阅&#39;有效&#39; =&gt;($ currentpage ==&#39;供应商&#39;)

<?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']);
    }
}

突出显示的供应商&#39;菜单项

enter image description here

完成所有这些修改后,字段无法编辑。无法输入任何已禁用的值。一旦我注释掉了渲染(&#39;菜单&#39;,[&#39;当前页面&#39; =&gt;&#39;供应商&#39;]); ?&gt; 表单字段可以编辑。

在supplier.php中注释了代码

enter image description here

评论后,渲染方法字段是可编辑的。

enter image description here

1 个答案:

答案 0 :(得分:1)

最后我找到了这个问题的答案。我通过消除Yii2默认的ActiveFrom小部件使用了Karthik ActiveForm小部件。现在我可以在字段中键入值。

谢谢大家的回复。