您的位置:首页 > 编程语言 > PHP开发

YII 小部件 yii小部件查看方法 小物件做的表单

2014-04-07 00:33 344 查看
要使用小部件,可以先到总文件去找 framework/yiilite文件里面搜索“CAtiveForm”

(如果觉得小部件的radio布局有点难看,可以在外面定义,具体可以在控制器里面定义)

如下:

function actionRegister(){
//实例化数据模型
$user_model=Admin::model();
$sex[1]='男';
$sex[2]='女';
$sex[3]='保密';
$this->render("register",array("user_model"=>$user_model,"sex"=>$sex));

} 那么在下面的表单中直接可以使用$sex对象了

<?php $form=$this->beginWidget('CActiveForm');?>
<table cellpadding="5" cellspacing="3"
style="text-align: left; width: 100%; border: 0;">
<tbody>
<tr>
<td style="width: 13%; text-align: right;">
<?php echo $form->label($user_model,'name')?>

</td>

<td style="width: 87%;">
<?php echo $form->textField($user_model,'name', array('class'=>'inputBg()','id'=>'username'));?>
<span style="color: red;"></span>
</td>
</tr>
<tr>
<td align="right">
<?php echo $form->label($user_model,'password')?>
<span class="required">*</span>
</td>

<td>
<?php echo $form->passwordField($user_model,'password', array('class'=>'inputBg()','id'=>'passowrd'));?>
</td>
</tr>
<tr>
<td align="right"><label for="User_password2">密码确认</label></td>
<td>
<input class="inputBg" size="25" name="User[password2]" id="User_password2" type="password" />
</td>

</tr>
<tr>
<td align="right"><?php echo $form->label($user_model,'email')?></td>
<td>
<?php echo $form->textField($user_model,'email', array('class'=>'inputBg()','id'=>'email'));?>
</td>
</tr>
<tr>

<td align="right"><?php echo $form->label($user_model,'QQ')?></td>
<td>
<?php echo $form->textField($user_model,'QQ', array('class'=>'inputBg()','id'=>'qq'));?>
</td>
</tr>
<tr>
<td align="right"><?php echo $form->label($user_model,'tel')?></td>
<td>
<?php echo $form->textField($user_model,'tel', array('class'=>'inputBg()','id'=>'tel'));?>
</td>
</tr>
<tr>
<!--radioButtonList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model,'sex')?></td>
<td>

                <!--------按钮默认<br/>结束 红色地方设置,$htmlOptions值,这样按钮才能在一行------->

            <?php echo $form->radioButtonList($user_model,'sex',$sex),array("separator"=>" ")?>
</td>
</tr>
<tr>
<!--dropDownList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model,'xueli')?></td>
<td><select name="User[user_xueli]" id="User_user_xueli">
<option value="1" selected="selected">-请选择-</option>
<option value="2">小学</option>

<option value="3">初中</option>
<option value="4">高中</option>
<option value="5">大学</option>
</select>
<div class="errorMessage" id="User_user_xueli_em_"
style="display: none"></div></td>
</tr>
<tr>
<!--checkBoxList($model,$attribute,$data,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model,'hoddy')?></td>

<td><input id="ytUser_user_hobby" type="hidden" value=""
name="User[user_hobby]" /> <span id="User_user_hobby"> <input
id="User_user_hobby_0" value="1" type="checkbox"
name="User[user_hobby][]" /> <label for="User_user_hobby_0">篮球</label> 
<input id="User_user_hobby_1" value="2" type="checkbox"
name="User[user_hobby][]" /> <label for="User_user_hobby_1">足球</label> 
<input id="User_user_hobby_2" value="3" type="checkbox"
name="User[user_hobby][]" /> <label for="User_user_hobby_2">排球</label> 
<input id="User_user_hobby_3" value="4" type="checkbox"
name="User[user_hobby][]" /> <label for="User_user_hobby_3">棒球</label>
</span></td>
</tr>
<tr>

<!--textArea($model,$attribute,$htmlOptions=array())-->
<td align="right"><?php echo $form->label($user_model,'introduce')?></td>
<td><textarea cols="50" rows="5" name="User[user_introduce]"
id="User_user_introduce"></textarea></td>
</tr>
<tr>
<td> </td>

<td align="left"><input name="Submit" value="提交"
class="us_Submit_reg" type="submit" /></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</tbody>
</table>

<?php $this->endWidget(); ?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: