Yii framework uses self-written html, without the widgets issue inherent in the framework

Source: Internet
Author: User
Tags php foreach
Recently, I started to study the PHP framework Yii, using the self-built zii. widgets, zii. widgets. grid and other components, although very powerful, but the style settings are not flexible enough, {code ...} I will ask you how to use your own html code in yii and write html code in views... recently, I started to study the PHP framework Yii,

Use the self-built zii. widgets, zii. widgets. grid, and other components,

Although powerful, style settings are not flexible enough,


  widget('zii.widgets.grid.CGridView', array(    'id'=>'content-grid',    'dataProvider'=>$model->search(),    'filter'=>$model,    'columns'=>array(        'id',        'title',        'times',        'content',        'dc_id',        array(            'class'=>'CButtonColumn',        ),    ),)); ?>

I would like to ask you how to use your own html code in yii,

Write html code in views. Here I will,

In addition, static data can be normally displayed,

But how to bind your html code to the fields in the data model in models,

This won't happen,

For example, how to display data in tables, lists, and pages?

Reply content:

Recently, I started to study the PHP framework Yii,

Use the self-built zii. widgets, zii. widgets. grid, and other components,

Although powerful, style settings are not flexible enough,


  widget('zii.widgets.grid.CGridView', array(    'id'=>'content-grid',    'dataProvider'=>$model->search(),    'filter'=>$model,    'columns'=>array(        'id',        'title',        'times',        'content',        'dc_id',        array(            'class'=>'CButtonColumn',        ),    ),)); ?>

I would like to ask you how to use your own html code in yii,

Write html code in views. Here I will,

In addition, static data can be normally displayed,

But how to bind your html code to the fields in the data model in models,

This won't happen,

For example, how to display data in tables, lists, and pages?

// In controllerpublic function actionIndex () {// initialize model $ mymodel = new Mymodel (); // obtain the filter condition $ criteria = $ mymodel-> search (); // if you do not need Criteria, you can directly write the condition Statement (findAll must be the same, but offset and limit must be calculated by yourself), for example, // $ count = Mymodel: model () -> count ("uid =: uid", array ("uid" => intval ($ _ GET ["uid"]); // processing pagination $ count = Mymodel: model ()-> count ($ criteria); $ pages = new CPagination ($ count); $ pages-> pageSize = 20; $ pages-> applyLimit ($ criteria); // get data $ data = Mymodel: model ()-> findAll ($ criteria ); $ this-> render ('index', array ("model" => $ mymodel, // The following part template does not use "pages" => $ pages, "data" => $ data,);} // in template, traverse $ data directly. The element is a Mymodel object instance. Use-> to access attributes.
  
  
Id;?> Name;?> Age;?> Gender;?>
    PageCount; $ p ++) {if ($ p = ($ pages-> currentPage + 1) {echo"
  • {$ P}
  • ";} Else {echo"
  • {$ P}
  • ";}}?>
Related Article

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.