Yii分页到json

I have a problem i can not find a way how do get pagination from php in json , here is my code :

            $type_name = substr(trim($_POST['type']),1);

            $criteria = new CDbCriteria();
            $count=ImageLibrary::model()->count($criteria);
            $pages=new CPagination($count);


            $pages->pageSize=10;
            $pages->applyLimit($criteria);
            $criteria->select = 'name,type';
            $criteria->condition = 'type=:type';
            $criteria->params = array('type' => $type_name);
            $model = ImageLibrary::model()->findAll($criteria);

            foreach( $model as $key => $data){
                $json_data[$key]['name'] = $data->name;
                $json_data[$key]['type'] = $data->type;
            }

            echo CJSON::encode($json_data);

i'm getting data , but i have no idea , how to bring to json :( , or if exist another way . Thank you for help !!!!

Don't have to do it that way. You can render out the whole HTML result in which you have the Pagination widget.

Example from one of my projects:

$count = AdStavke::model()->count($criteria);
$pages = new CPagination($count);

$pages->pageSize = 20;
$pages->applyLimit($criteria);

$stavke = AdStavke::model()->findAll($criteria);

if (sizeof($stavke)) {
    $response = array(
        'success' => true,
        'html' => $this->renderPartial($types[$type]['view_file'], array(
            'model' => $stavke,
            'pages' => $pages,
            'nezaduzene' => true,
                ), true),
    );
}

In the View:

<div id="appTable">
    <table class="tablesorter stavke zaduzene table table-striped table-hover table-condensed table-bordered">
        <thead>
            <tr class="descriptioner">
                <th colspan="9">
                    <div class="pull-left">
                        Lista <span class="label label-warning" style="font-size: 14px;">zaduženih</span> stavki u: <?= $model[0]->stavka->vrsta->naziv; ?>
                    </div>
                    <div class="pull-right">
                        <?php
                        $this->widget('CLinkPager', array(
                            'htmlOptions' => array(
                                'class' => 'yiiPager yiiPager_2',
                            ),
                            'pages' => $pages,
                            'header' => false,
                            'firstPageLabel' => 'Prva',
                            'lastPageLabel' => 'Zadnja',
                            'prevPageLabel' => 'Prethodna',
                            'nextPageLabel' => 'Sljedeća',
                        ));
                        ?>
                    </div>
                    <div class="clearfix"></div>
                </th>
            </tr>
        </thead>
    </table>
</div>

And you can send a simple AJAX request to change your entrie view with Updated-Pagination:

$.post('/aplikacije/ajax/fetch', {
    submit: true,
    type: 'stanja',
    seek: mapped.data('stanje'),
    vrsta_id: $('.vrstex.active').first().data('vid'),
    q: _mapped.val()
}, function(data) {
    if(data.success) {
        $('#appTable').html( data.html );
    }
}, 'json');

Note: This code is derived from one of my live-projects and from this you can get the idea how to do Yii-pagination with AJAX.