php active控件,php – 使用TbActiveForm选择列表中的动态选项
我在控制器中有以下代碼,
$model=new Guessgame('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['Guessgame']))
$model->attributes=$_GET['Guessgame'];
$this->render('admin',array(
'model'=>$model,
));
在視圖文件中,
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'project1-form',
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data','class' => 'well'),
'type' => 'horizontal',
'enableAjaxValidation' => false,
'enableClientValidation' => true,
'clientOptions' => array(
'validateOnSubmit' => true,
)
)); ?>
Fields with * are required.
<?php echo $form->errorSummary($model); ?>
<?php echo $form->dropDownListRow($model,'type',array('logo'=>'Logo','apaters'=>'Apaters','text'=>'Text'),array('class'=>'span5','maxlength'=>255)); ?>
上面的示例列表項是靜態的(徽標,分隔符和文本.
但我想從數據庫中獲取動態值.請幫我.
解決方法:
你可以在模型中寫下函數來從db獲取值
function getValues(){
$crit = new CDbCriteria();
$crit->select = 'name';
$crit->order = 'name';
$data = YourModel::model()->findAll($crit);
$result = CHtml::listData($data,'id','name');
return $result;
}
在視野中
echo $form->dropDownListRow($model, 'type', YourModel::model()->getValues(), array('class'=>'span5', 'maxlength'=>255));
?>
希望這樣可以解決您的問題
標簽:php,yii
來源: https://codeday.me/bug/20190711/1433880.html
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的php active控件,php – 使用TbActiveForm选择列表中的动态选项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ipython怎么安装_ipython的
- 下一篇: linux安装python2环境_Pyt