1. 云栖社区>
  2. PHP教程>
  3. 正文

Yii一般控件使用代码

作者:用户 来源:互联网 时间:2017-12-01 19:15:35

控件yii代码使用

Yii一般控件使用代码 - 摘要: 本文讲的是Yii一般控件使用代码, View------------------------------------------------- <?php$this->pageTitle=Yii::app()->name . ' - 总结';$this-&


View
-------------------------------------------------


<?php
$this->pageTitle=Yii::app()->name . ' - 总结';
$this->breadcrumbs=array('控件使用总结',);
?>

控件使用总结


<?php echo $form->labelEx($model,'textfiled'); ?> <?php echo $form->textField($model,'textfiled'); ?> <?php echo $form->error($model,'textfiled'); ?>
<?php echo $form->labelEx($model,'password'); ?> <?php echo $form->passwordField($model,'password'); ?> <?php echo $form->error($model,'password'); ?>
<?php echo $form->labelEx($model,'checkBox'); ?> <?php echo $form->checkBox($model,'checkBox'); ?> <?php echo $form->error($model,'checkBox'); ?>
<?php echo $form->labelEx($model,'checkBoxList'); ?> <?php echo $form->checkBoxList($model,'checkBoxList',WidgetForm::getCheckBoxListContent()); ?> <?php echo $form->error($model,'checkBoxList'); ?>
<?php echo $form->labelEx($model,'dropDownList'); ?> <?php echo $form->dropDownList($model, 'dropDownList', WidgetForm::getDropDownListContent()); ?> <?php echo $form->error($model,'dropDownList'); ?>
<?php echo $form->labelEx($model,'radioButtonList'); ?> <?php echo $form->radioButtonList($model, 'radioButtonList', WidgetForm::getRadioButtonListContent());?> <?php echo $form->error($model,'radioButtonList'); ?>
<?php echo CHtml::submitButton('Submit'); ?>


<?php
if (isset($message)){
echo $message ;
}
?>

<?php $this->endWidget(); ?>

Form
-------------------------------------------------
class WidgetForm extends CFormModel {
public $textfiled; // 文本框
public $password; // 密码框
public $dropDownList; // 下拉列表
public $checkBox; // 单复选框
public $checkBoxList; //多复选框
public $radioButtonList; // 单选列表
public function rules() {
return array(
array('textfiled, password, dropDownList, checkBox, checkBoxList, radioButtonList','safe'),
);
}
public function attributeLabels() {
return array(
'textfiled' => '文本框',
'password' => '密码框',
'dropDownList' => '下拉列表',
'checkBox' => '单选列表',
'checkBoxList' => '多复选框',
'radioButtonList' => '单选按钮',
);
}
public static function getDropDownListContent(){
$result = array();
for($i=0 ; $i<10; $i++){
$result[$i]='DropDown'.$i;
}
return $result;
}
public static function getCheckBoxListContent(){
$result = array();
for($i=0 ; $i<3; $i++){
$result[$i]='CheckBox'.$i;
}
return $result;
}
public static function getRadioButtonListContent(){
$result = array();
for($i=0 ; $i<3; $i++){
$result[$i]='RadioButton'.$i;
}
return $result;
}
}Controller
-------------------------------------------------
class WidgetController extends Controller {
public function actionIndex() {
$model = new WidgetForm();
if (isset($_POST['WidgetForm'])) {
$model->attributes = $_POST['WidgetForm'];
$message ="";
$message = $message ."
文本框:". getType($model->textfiled) ."". $model->textfiled;
$message = $message ."
密码框:". getType($model->password) ."". $model->password;
$message = $message ."
单复选框:". getType($model->checkBox) ."". $model->checkBox;
$message = $message ."
多复选框:". getType($model->checkBoxList) ."". print_r($model->checkBoxList,true);
$message = $message ."
下拉列表:". getType($model->dropDownList) ."". $model->dropDownList;
$message = $message ."
单选列表:". getType($model->radioButtonList) ."". $model->radioButtonList;
$this->render('index', array('model' => $model, 'message' => $message));
} else{
$this->render('index', array('model' => $model));
}
}
}

以上是云栖社区小编为您精心准备的的内容,在云栖社区的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索控件 , yii , 代码 , 使用 ,以便于您获取更多的相关知识。