Php 验证Yi2 always callback integer中的复选框列表必须为整数
在yii中: 型号Php 验证Yi2 always callback integer中的复选框列表必须为整数,php,yii,Php,Yii,在yii中: 型号 class LinkReqTipe extends \yii\db\ActiveRecord public static function tableName() { return 'link_req_tipe'; } public function rules() { return [ [['tipe_id'], 'integer'], [['tipe_id'], 'required'], [['reques
class LinkReqTipe extends \yii\db\ActiveRecord
public static function tableName()
{
return 'link_req_tipe';
}
public function rules()
{
return [
[['tipe_id'], 'integer'],
[['tipe_id'], 'required'],
[['request_id'], 'exist', 'skipOnError' => true, 'targetClass' => Request::className(), 'targetAttribute' => ['request_id' => 'id']],
[['tipe_id'], 'exist', 'skipOnError' => true, 'targetClass' => TipeRequest::className(), 'targetAttribute' => ['tipe_id' => 'id']],
];
}
\u form.php
echo $form->field($modelLinkReqTipe, 'tipe_id')->checkBoxList(
ArrayHelper::map(TipeRequest::find()->all(), 'id', 'nama_tipe'));
它生成html(firebug请参见)
调试它(选中一个复选框):
调试它(选中两个复选框):
请注意。可能是因为它是一个数组,请尝试使用
['tipe_id','each','rule'=>['integer']],
tipe_id无效IDTW刚才注意到,您使用的是name=“LinkReqTipe[tipe_id]”
然后作为数组name=“LinkReqTipe[tipe_id][]”
作为值或数组使用,而不是两者都使用……那么,我应该更改什么呢?
<div class="form-group field-linkreqtipe-tipe_id required">
<label class="control-label col-sm-3">Tipe ID</label>
<div class="col-sm-9">
<input name="LinkReqTipe[tipe_id]" value="" type="hidden">
<div id="linkreqtipe-tipe_id">
<div class="checkbox">
<label>
<input name="LinkReqTipe[tipe_id][]" value="1" type="checkbox"> Perbaikan
</label>
</div>
<div class="checkbox">
<label>
<input name="LinkReqTipe[tipe_id][]" value="2" type="checkbox"> Permintaan
</label>
</div>
</div>
<div class="help-block help-block-error "></div>
</div>
</div>
if ($modelLinkReqTipe->load($request->post())) {
## validate
$valid = $modelLinkReqTipe->validate(['tipe_id']);
....some code
}
modelLinkReqTipe Object { tipe_id=[1]}
tipe_id ["1"]
0 "1"
modelLinkReqTipe Object { tipe_id=[2]}
tipe_id ["2"]
0 "1"
1 "2"