Modify the model and view after adding fields to yii

Source: Internet
Author: User

Rules:

Array ('new field', 'safe ', 'on' => 'search ')

1. array ('new field', 'safe ') // If You Want To input this field, add it,

2. array ('new field', 'Numerical '), // if it is a number

3. array ('new field', 'length', 'Max' => 100), // if it is text

1, 2, 3 add at least one appropriate field to save the new field.

 

AttributeLabels:

'New field' => 'new field', // about the displayed label

 

Search:

$ Criteria-> compare ('new field', $ this-> new field, true); // The gridview is searched here.

Example of adding a gridview:

Array ('name' => 'new field', 'filter' => $ array/*, 'type' => 'Raw' // it seems that this is not required for the new YII version, as long as the filter is an array */),

From above: http://jiangzhixiang123.blog.163.com/blog/static/278020622011111263110296/

In addition, the view modification method:

View. php:

$ This-> widget ('zii. widgets. cdetailview', array (
'Data' => $ model,
'Bubuckets' => array (
'Id ',

'New field ',

)

LIST _ view. php:

<B> <? Php echo CHtml: encode ($ data-> getAttributeLabel ('new field');?> : </B>
<? Php echo CHtml: encode ($ data-> new field);?>
<Br/>

Form _ form. php:

<Div class = "row">
<? Php echo $ form-> labelEx ($ model, 'new field');?>
<? Php echo $ form-> textField ($ model, 'new field', array ('SIZE' => 60, 'maxlength' => 255);?>
<? Php echo $ form-> error ($ model, 'new field');?>
</Div>

Search _ search. php:

<Div class = "row">
<? Php echo $ form-> label ($ model, 'new field');?>
<? Php echo $ form-> textField ($ model, 'new field', array ('SIZE' => 60, 'maxlength' => 255);?>
</Div>

OK. Is everything going well ?!

When this function is used again today

When a field is added, the attribute "Blog. name" is not defined.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.