Json_decode

Hi

I have a josn file http://xxx.com/api/feed/499912.json?multi_brand=1

And successfully get the data and display in Cgridview but only can get page 1 data only. Tat have total of 5 pages

Content of json file like below

{

items: [],

total_page: 5,

total_item: 93,

page: 1,

paging: {

next: "http://xxx.com/api/feed/499912.json?multi_brand=1&page=2"

},

brand: {}

}

So what should i do to get all the data from total 5 pages?

My controller as below :

   $data = array();


    $data = file_get_contents('http://xxx.com/api/feed/499912.json?multi_brand=1');


    $data = json_decode($data, true);

You should get "page" param passed to action controller when you go forward in CGridView pagination.

Then you will pass this param to json request to get the new content.

Sorry i’m new @_@ can provide some sample of coding?

In action controller




public function actionGrid()

{

    $page = Yii::app()->request->getQuery('page');


    ...

}



ok …i try and c…but sorry i’m really noob…so if possible can provide me more details code. Thank you very much

Post your code so I can add suggestions.

sample file

{

items: [],

total_page: 5,

total_item: 93,

page: 1,

paging: {

next: "http://xxx.com/api/feed/499912.json?multi_brand=1&page=2"

},

brand: {}

}

ok in my controller

   $data = array();


    $data = file_get_contents('http://xxx.com/api/feed/499912.json?multi_brand=1');


    $data = json_decode($data, true); 


    $data = array_shift($data); //move up level





    


    $dataProvider = new CArrayDataProvider($data, array(


         'keyField' => 'nid',


         'pagination' => array(


         'pageSize'=>20,


            ),


        ));


    


$this->render('index',array(


	'dataProvider' => $dataProvider,


	));


}

So what should i do next?




<?php


public function actionGrid()

{

	// 'page' is the parameter passed from the CGridView when you change page in pagination control

	$page = Yii::app()->request->getQuery('page');


	$data = array();

	$data = file_get_contents('http://xxx.com/api/feed/499912.json?multi_brand=1&page='.$page);

	$data = json_decode($data, true);

	$data = array_shift($data); //move up level

	

	// you have to populate this from json

	$totalItemFromJson = ...

	

	$dataProvider = new CArrayDataProvider($data, array(

	'keyField' => 'nid',

	'pagination' => array(

		'pageSize'=>20,

		'currentPage' => $page

		'itemCount' => $totalItemFromJson

	),

	));

	

	$this->render('index',array(

	'dataProvider' => $dataProvider,

	));

	}

}

?>



// you have to populate this from json

    &#036;totalItemFromJson = ...

Sorry totally noob…wat should i put here?

Ok, listen bro Fabrizio answer was excellent, but probably too advanced. I suggest you to use ajax to load your JSon and later usin JQuery serialize to your Grid. I can explain a little more if you’re interested…

Please help with details coding…i totally noob @_@ thanks for your help

Any way I recommend you to study a little more the framework cause is hard to try to help you like this… One more time Fabrizio gave you an excellent and clear answer but you have to be ready to get it…

@_@ i’m trying… but hopefully bro Fabrizio can help me

Here my friend some piece of code with ajax and a GridView:

Hello my friend I found this post I made a few days ago, I think it can be helpfull

Quick example using Ajax with an action (on php server-side of course) and JQuery on the client side.

View:

Yii::app()->clientScript->registerScript(‘dataScript’, "

function upData_click() {

var url = ‘index.php?r=MyExample/getJSonData’;

$.ajax({

url: url,

type: ‘post’,

success: function(resp){

$(’#MyGrid-grid’).yiiGridView(‘update’, {

resp: $(this).serialize()

});

return false;

},

error: function(){

alert('it’s been an error);

}

});

});

}

");

Controller…

public function actionGetJSonData($id)

{

$model = MyModel::model()->find(‘ID = ?’, array($id));

header("Content-type: application/json");

echo CJSON::encode($model);

}

Tell meif it work I’ll be on-line later… Good luck my friend…we’re in communication…

You’re in two posts with similar bases problems… try to find a connection with the code I sent you in both posts. Check for both…