YII 控件使用笔记

来源:互联网 发布:c语言入门视频百度云 编辑:程序博客网 时间:2024/05/21 09:11

textField

sample:

   1: <?php echo $form->textField($model, 'var_name',array('size'=>70));?>
上面就创建了一个输入框,后面的‘size’ 则设置输入框的显示长度。

checkBoxList

  sample:

   1: <;?php echo $form->checkBoxList($model,
   2:                                'var_name',
   3:                                 data_array,
   4:                                 $htmloption);?>

checkbox的数据,默认是垂直显示的,如果想横向显示,则如下处理

   1: <;?php echo $form->checkBoxList($model,
   2:                                'var_name',
   3:                                data_array,
   4:                                array('separator'=>;' ',
   5:                                      'labelOptions'=>array('style'=>'display:inline')
   6:                                      )
   7:                                ); ?>

上面的最后一组参数,separator是修改的数据的分割符号,后面可以用空格(&nbsp) 来分割。

                           labelOptions  display:inline是设置显示在同一行。

如果设置checkBoxList默认选中的值,则可以在相应的Controller中设置值,

  比如在Controller中设置$this->model->var_name=array(0,1)

  则默认选中0和1对应的值。

 

radioButtonList

     <?php $debug_radio=$form->radioButtonList($model,                        'debug_type',                       RedirectForm::$DEBUG_TYPES,                       array('template'=>'<li style="display:inline-block;width:150px;">{input}{label}</li>',                             'separator'=>''));           $debug_radio= str_replace("<label", "<span", $debug_radio);            $debug_radio= str_replace("</label", "</span", $debug_radio);            echo $debug_radio;                            ?>
display:inline-block 设置在一行显示, width设置间隔。 下面的将label替换为span 将其显示在一行内