Yii代码片段

来自tomtalk
跳转至: 导航搜索

yii的gridview使用

$this->widget('zii.widgets.grid.CGridView', array(
    'id' => 'xx-xx-grid',
    'dataProvider' => $model->search(),
    'filter' => $model,
    'pager' => array(
        'class' => 'CLinkPager',
        'nextPageLabel' => '下一页',
        'prevPageLabel' => '上一页',
        'header' => '',
    ),
    'summaryText' => '<font color=#0066A4>显示{start}-{end}条.共{count}条记录,当前第{page}页</font>',
    'columns' => array(
        array(
            'name' => 'id',
            'htmlOptions' => array('width' => '25'),
            'sortable' => false,
        ),
        array(
            'class' => 'CButtonColumn',
            'template' => '{view} {update}',
            'viewButtonOptions' => array('title' => '查看'),
            'updateButtonOptions' => array('title' => '修改'),
        ),
        array(
            'class' => 'CButtonColumn',
            'header' => '首页展示',
            'template' => '{add} {del}',
            'buttons' => array(
                'add' => array(
                    'label' => '展示', // text label of the button
                    'url' => 'Yii::app()->controller->createUrl("focus/create",array("id"=>$data->primaryKey,"type"=>1))', // a PHP expression for generating the URL of the button
                    'imageUrl' => 'http://s.maylou.com/common/images/ysh.jpg', // image URL of the button. If not set or false, a text link is used
                    'options' => array('style' => 'cursor:pointer;'), // HTML options for the button tag
                    'click' => $click, // a JS function to be invoked when the button is clicked
                    'visible' => 'SiteRecommend::isItemInTypeAndId(1, $data->id)?false:true',
                ),
                'del' => array(
                    'label' => '取消展示', // text label of the button
                    'url' => 'Yii::app()->controller->createUrl("focus/delete",array("id"=>$data->primaryKey,"type"=>1))', // a PHP expression for generating the URL of the button
                    'imageUrl' => 'http://s.maylou.com/common/images/yzhu.jpg', // image URL of the button. If not set or false, a text link is used
                    'options' => array('style' => 'cursor:pointer;'), // HTML options for the button tag
                    'click' => $click, // a JS function to be invoked when the button is clicked
                    'visible' => 'SiteRecommend::isItemInTypeAndId(1, $data->id)?true:false',
                )
            ),
        ),
    ),
));