activeForm生成的html结构,本地与线上不同 [ 2.0 版本 ]
这是view视图部分:
<div class="perfect-information">
<?php
$form = ActiveForm::begin([
'id' => 'otherinfo',
'action' => ['save-perfect-information', 'id' => $model->id],
'type' => ActiveForm::TYPE_HORIZONTAL,
'formConfig' => ['labelSpan' => 5, 'deviceSize' => ActiveForm::SIZE_TINY]
]);
?>
<?= $form->field($model, 'username')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'gender')->dropDownList($model->CommAyy()['gender'], ['maxlength' => true]) ?>
<?= $form->field($model, 'customer_telephone')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'national')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'issued')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'valid')->textInput(['maxlength' => 10, 'placeholder' => '2000.01.01', 'style' => 'width:100%;', 'value' => isset($model->valid) ? isset(explode('-', $model->valid)[0]) ? explode('-', $model->valid)[0] : '' : ''])->label('证件有效起始') ?>
<?= $form->field($model, 'valid_end')->textInput(['maxlength' => 10, 'placeholder' => '2020.01.01 或 长期', 'style' => 'width:100%;', 'value' => isset($model->valid) ? isset(explode('-', $model->valid)[1]) ? explode('-', $model->valid)[1] : '' : ''])->label('证件有效结束'); ?>
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
<?php ActiveForm::end(); ?>
</div>
然后这是线上生成的的html结构:
<div class="perfect-information">
<form id="otherinfo" class="form-horizontal kv-form-horizontal" action="/index.php?r=credit-orders%2Fsave-perfect-information&id=290" method="post"> <div class="form-group field-creditorders-username">
<label class="control-label col-xs-5" for="creditorders-username">客户姓名</label>
<div class="col-xs-7"><input type="text" id="creditorders-username" class="form-control" name="CreditOrders[username]"></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">姓名格式不正确!</div></div>
</div>
<div class="form-group field-creditorders-gender">
<label class="control-label col-xs-5" for="creditorders-gender">性别</label>
<div class="col-xs-7"><select id="creditorders-gender" class="form-control" name="CreditOrders[gender]" maxlength="">
<option value="1">男</option>
<option value="0">女</option>
</select></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block"></div></div>
</div>
<div class="form-group field-creditorders-customer_telephone">
<label class="control-label col-xs-5" for="creditorders-customer_telephone">客户手机号</label>
<div class="col-xs-7"><input type="text" id="creditorders-customer_telephone" class="form-control" name="CreditOrders[customer_telephone]"></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">号码格式不正确!</div></div>
</div>
<div class="form-group field-creditorders-national">
<label class="control-label col-xs-5" for="creditorders-national">民族</label>
<div class="col-xs-7"><input type="text" id="creditorders-national" class="form-control" name="CreditOrders[national]"></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">不能为空.</div></div>
</div>
<div class="form-group field-creditorders-issued">
<label class="control-label col-xs-5" for="creditorders-issued">证件签发机关</label>
<div class="col-xs-7"><input type="text" id="creditorders-issued" class="form-control" name="CreditOrders[issued]" value=""></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">不能为空.</div></div>
</div>
<div class="form-group field-creditorders-valid">
<label class="control-label col-xs-5" for="creditorders-valid">证件有效起始</label>
<div class="col-xs-7"><input type="text" id="creditorders-valid" class="form-control" name="CreditOrders[valid]" value="" maxlength="10" placeholder="2000.01.01" style="width:100%;"></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">格式例如:"2000.01.01",注意不能有空格.!</div></div>
</div>
<div class="form-group field-creditorders-valid_end">
<label class="control-label col-xs-5" for="creditorders-valid_end">证件有效结束</label>
<div class="col-xs-7"><input type="text" id="creditorders-valid_end" class="form-control" name="CreditOrders[valid_end]" value="" maxlength="10" placeholder="2020.01.01 或 长期" style="width:100%;"></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">格式例如:"2020.01.01"或"长期",注意不能有空格.!</div></div>
</div>
<div class="form-group field-creditorders-address">
<label class="control-label col-xs-5" for="creditorders-address">身份证地址</label>
<div class="col-xs-7"><input type="text" id="creditorders-address" class="form-control" name="CreditOrders[address]" value=""></div>
<div class="col-xs-offset-5 col-xs-7"></div>
<div class="col-xs-offset-5 col-xs-7"><div class="help-block">不能为空.</div></div>
</div>
</form></div>
这是本地生成的html结构:
<div class="perfect-information">
<form id="otherinfo" class="form-horizontal kv-form-horizontal" action="/qbtcredit/frontend/web/index.php?r=credit-orders%2Fsave-perfect-information&id=21342" method="post" role="form">
<input type="hidden" name="_csrf" value="N2FBeU1iX3RUAhI6Jg4XI3IJMC4nVToiYVYOExdTABt5UmxIFQ8dQg=="> <div class="form-group field-creditorders-username">
<label class="control-label col-xs-5" for="creditorders-username">客户姓名</label>
<div class="col-xs-7">
<input type="text" id="creditorders-username" class="form-control" name="CreditOrders[username]">
<div class="help-block">姓名格式不正确!</div>
</div>
</div>
<div class="form-group field-creditorders-gender">
<label class="control-label col-xs-5" for="creditorders-gender">性别</label>
<div class="col-xs-7">
<select id="creditorders-gender" class="form-control" name="CreditOrders[gender]" maxlength="">
<option value="1">男</option>
<option value="0">女</option>
</select>
<div class="help-block"></div>
</div>
</div>
<div class="form-group field-creditorders-customer_telephone">
<label class="control-label col-xs-5" for="creditorders-customer_telephone">客户手机号</label>
<div class="col-xs-7">
<input type="text" id="creditorders-customer_telephone" class="form-control" name="CreditOrders[customer_telephone]">
<div class="help-block">号码格式不正确!</div>
</div>
</div>
<div class="form-group field-creditorders-national">
<label class="control-label col-xs-5" for="creditorders-national">民族</label>
<div class="col-xs-7">
<input type="text" id="creditorders-national" class="form-control" name="CreditOrders[national]" value="">
<div class="help-block">不能为空.</div>
</div>
</div>
<div class="form-group field-creditorders-issued">
<label class="control-label col-xs-5" for="creditorders-issued">证件签发机关</label>
<div class="col-xs-7">
<input type="text" id="creditorders-issued" class="form-control" name="CreditOrders[issued]" value="">
<div class="help-block">不能为空.</div>
</div>
</div>
<div class="form-group field-creditorders-valid">
<label class="control-label col-xs-5" for="creditorders-valid">证件有效起始</label>
<div class="col-xs-7">
<input type="text" id="creditorders-valid" class="form-control" name="CreditOrders[valid]" value="" maxlength="10" placeholder="2000.01.01" style="width:100%;">
<div class="help-block">格式例如:"2000.01.01",注意不能有空格.!</div>
</div>
</div>
<div class="form-group field-creditorders-valid_end">
<label class="control-label col-xs-5" for="creditorders-valid_end">证件有效结束</label>
<div class="col-xs-7">
<input type="text" id="creditorders-valid_end" class="form-control" name="CreditOrders[valid_end]" value="" maxlength="10" placeholder="2020.01.01 或 长期" style="width:100%;">
<div class="help-block">格式例如:"2020.01.01"或"长期",注意不能有空格.!</div>
</div>
</div>
<div class="form-group field-creditorders-address">
<label class="control-label col-xs-5" for="creditorders-address">身份证地址</label>
<div class="col-xs-7">
<input type="text" id="creditorders-address" class="form-control" name="CreditOrders[address]" value="">
<div class="help-block">不能为空.</div>
</div>
</div>
</form></div>
让我很困惑的就是为什么线上和本地的html层级结构不一样(input标签和div.help-block不在同一个div内,线上还多了一个空的div等);视图里使用的是use kartik\form\ActiveForm,但这个插件继承了\yii\widgets\ActiveForm,这个表单是弹窗表单,应该不影响吧。
38223 补充于 2016-10-10 14:13
现在修改视图文件在本地可以实现和线上一样的层级结构,但具体为什么会出现这种情况还是不懂...
<?= $form->field($model, 'username', ['template' => '{label} <div class="col-xs-7">{input}</div><div class="col-xs-offset-5 col-xs-7"></div><div class="col-xs-offset-5 col-xs-7">{error}</div>'])->textInput(['maxlength' => true]) ?>
共 3 个回答
-
wutongshuzly 回答于 2016-10-10 11:18 举报
不知道是不是和bootstrap有关系,从bootstrap方向调查下吧
38223
注册时间:2016-10-31
最后登录:1970-01-01
在线时长:0小时0分
最后登录:1970-01-01
在线时长:0小时0分
- 粉丝1
- 金钱70
- 威望0
- 积分70