YII学习第二十五天,数据库添加新字段之后model类的修改
rules:
array('新字段','safe','on'=>'search')
1、array('新字段', 'safe')//这个如果是要用户输入的话,要加一下,
2、array('新字段', 'numerical'),//如果是数字的话
3、array('新字段', 'length', 'max'=>100),//如果是文本
1、2、3适当的最少要加一条,新字段才会被保存。
?
attributeLabels:
'新字段'=>'新字段',//关于显示的label
?
search:
$criteria->compare('新字段',$this->新字段,true);//gridview靠的就是这里搜索的。
给个gridview的添加例子:
array('name'=>'新字段','filter'=>$array/*,'type'=>'raw'//貌似新版的YII不用这项,只要filter是个数组就可以了*/),
?
另外视图的改法:
详情页?view.php:
$this->widget('zii.widgets.CDetailView',?array(
????'data'=>$model,
????'attributes'=>array(
????????'id',
????????'新字段',
)
列表?_view.php:
<b><?php?echo?CHtml::encode($data->getAttributeLabel('新字段'));??>:</b>
????<?php?echo?CHtml::encode($data->新字段);??>
?<br?/>
?
表单?_form.php:
<div?class="row">
????????<?php?echo?$form->labelEx($model,'新字段');??>
????????<?php?echo?$form->textField($model,'新字段',array('size'=>60,'maxlength'=>255));??>
????????<?php?echo?$form->error($model,'新字段');??>
????</div>
?
搜索?_search.php:
<div?class="row">
????????<?php?echo?$form->label($model,'新字段');??>
????????<?php?echo?$form->textField($model,'新字段',array('size'=>60,'maxlength'=>255));??>
???</div>
?
ok,一切可顺利?!
?
今天再次用到这个功能时,出现了
增加字段后显示?:属性?"Blog.name"?未被定义.