溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

CGridView怎么在Yii 框架中使用

發布時間:2021-01-15 16:46:35 來源:億速云 閱讀:211 作者:Leah 欄目:開發技術

CGridView怎么在Yii 框架中使用?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。

CGridView的功能是用來顯示的數據列表。它支持排序,分頁,和AJAX數據請求。

CGridView最好使用 data provider,最好是 CActiveDataProvider 。

簡單代碼如下:

$dataProvider=new CActiveDataProvider('Post');
$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
));

詳細示例:

$this->widget('zii.widgets.grid.CGridView', array(
  'dataProvider'=>$dataProvider,
  'columns'=>array(
    'title',     // display the 'title' attribute
    'category.name', // display the 'name' attribute of the 'category' relation
    'content:html',  // display the 'content' attribute as purified HTML
    array(      // display 'create_time' using an expression
      'name'=>'create_time',
      'value'=>'date("M j, Y", $data->create_time)',
    ),
    array(      // display 'author.username' using an expression
      'name'=>'authorName',
      'value'=>'$data->author->username',
    ),
    array(      // display a column with "view", "update" and "delete" buttons
      'class'=>'CButtonColumn',
    ),
  ),
));

屬性說明:

actionPrefix 方法前輟

afterAjaxUpdate AJAX成功響應后調用的JAVASCRIPT函數

ajaxUpdate 是否啟用AJAX請求數據

ajaxUpdateError AJAX失敗響應后調用的JAVASCRIPT函數

ajaxUrl AJAX請求的URL

ajaxVar AJAX請求,使用GET方式傳送的變量

baseScriptUrl 視圖資源的URL

beforeAjaxUpdate 在AJAX調用之前調用的JAVASCRIPT函數

blankDisplay 列標題為空顯示的內容

columns 內容列有配置

controller 控制器

cssFile 視圖的樣式

dataProvider 視圖的數據

emptyText 內容為空顯示的信息

filterPosition 搜索框所在的位置

關于CGridView怎么在Yii 框架中使用問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女