Yii CHtml::checkBoxList中的其他值

Yii CHtml::checkBoxList中的其他值,yii,Yii,在CHtml::checkBoxList中是否有其他值的解决方案 现在我这样做: <?php echo CHtml::checkBoxList( 'tinyList', '', array("value1" => "label1", "value2" => "label2", "value3" => "label3"), array(

在CHtml::checkBoxList中是否有其他值的解决方案

现在我这样做:

    <?php
        echo CHtml::checkBoxList(
            'tinyList', 
            '', 
            array("value1" => "label1", "value2" => "label2", "value3" => "label3"),
            array(
                'template'  => '<tr><td><img src="{imagePath}" /></td><td>{label}</td><td>{quantity}</td><td>{input}</td></tr>',
                'container' => 'tbody'
                ));
    ?>

我得到了这个结果:

     <tbody id="tinyList">
         <tr>
             <td><img src="{imagePath}" /></td>
             <td><label for="tinyList_0">label1</label></td>
             <td>{quantity}</td>
             <td><input value="value1" id="tinyList_0" type="checkbox" name="tinyList[]" /></td>
         </tr>
         <tr>
             <td><img src="{imagePath}" /></td>
             <td><label for="tinyList_1">label2</label></td>
             <td>{quantity}</td>
             <td><input value="value2" id="tinyList_1" type="checkbox" name="tinyList[]" /></td>
         </tr>
         <tr>
             <td><img src="{imagePath}" /></td>
             <td><label for="tinyList_2">label3</label></td>
             <td>{quantity}</td>
             <td><input value="value3" id="tinyList_2" type="checkbox" name="tinyList[]" /></td>
         </tr>
     </tbody>        

标签1
{数量}
标签2
{数量}
标签3
{数量}

(如何)我可以填充缺少的部分“imagePath”和“quantity”?

只有两个占位符可以传递到
CHtml::checkBoxList
-
{label}
{input}

CHtml::checkBoxList
imagePath
quantity
一无所知。 因此,它无法将它们添加到模板中

我能看到的唯一解决方案是使用带有自定义视图文件的
CListView
widget,它将代表您需要的tempate

此外,您还需要定义具有所有必需值的数据结构。 就这样吧:

$rawData=array(
    array(
        'inputValue'=>'value 1',
        'inputLabel'=>'label 1',
        'quantity'=>23,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 2',
        'inputLabel'=>'label 2',
        'quantity'=>21,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 3',
        'inputLabel'=>'label 3',
        'quantity'=>56,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    )
);
<table>
<?php
    $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>new CArrayDataProvider($rawData, array('keyField'=>false)),
        'itemView'=>'_item',
        'template'=>'{items}'
    ));
?>
</table>
然后主视图文件将如下所示:

$rawData=array(
    array(
        'inputValue'=>'value 1',
        'inputLabel'=>'label 1',
        'quantity'=>23,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 2',
        'inputLabel'=>'label 2',
        'quantity'=>21,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 3',
        'inputLabel'=>'label 3',
        'quantity'=>56,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    )
);
<table>
<?php
    $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>new CArrayDataProvider($rawData, array('keyField'=>false)),
        'itemView'=>'_item',
        'template'=>'{items}'
    ));
?>
</table>
上面的代码给了我一个表格,每行有图像、标签、数字和复选框

另外,
CGridView
可能会有帮助


我希望这有帮助。

只有两个占位符可以传递到
CHtml::checkBoxList
-
{label}
{input}

CHtml::checkBoxList
imagePath
quantity
一无所知。 因此,它无法将它们添加到模板中

我能看到的唯一解决方案是使用带有自定义视图文件的
CListView
widget,它将代表您需要的tempate

此外,您还需要定义具有所有必需值的数据结构。 就这样吧:

$rawData=array(
    array(
        'inputValue'=>'value 1',
        'inputLabel'=>'label 1',
        'quantity'=>23,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 2',
        'inputLabel'=>'label 2',
        'quantity'=>21,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 3',
        'inputLabel'=>'label 3',
        'quantity'=>56,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    )
);
<table>
<?php
    $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>new CArrayDataProvider($rawData, array('keyField'=>false)),
        'itemView'=>'_item',
        'template'=>'{items}'
    ));
?>
</table>
然后主视图文件将如下所示:

$rawData=array(
    array(
        'inputValue'=>'value 1',
        'inputLabel'=>'label 1',
        'quantity'=>23,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 2',
        'inputLabel'=>'label 2',
        'quantity'=>21,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    ),
    array(
        'inputValue'=>'value 3',
        'inputLabel'=>'label 3',
        'quantity'=>56,
        'imagePath'=>'https://www.google.com/images/srpr/logo4w.png'
    )
);
<table>
<?php
    $this->widget('zii.widgets.CListView', array(
        'dataProvider'=>new CArrayDataProvider($rawData, array('keyField'=>false)),
        'itemView'=>'_item',
        'template'=>'{items}'
    ));
?>
</table>
上面的代码给了我一个表格,每行有图像、标签、数字和复选框

另外,
CGridView
可能会有帮助


我希望这能有所帮助。

Chechboxlist应该只是一个复选框列表。单独填写表格。Chechboxlist应该是一个复选框列表。分别填写表格。