Wednesday, May 8, 2019

PHP Fetch data from database and encode into JSON format Yii framework



I'm kinda struggling with yii framework. I would like to connect to mobile app from my php server. How should I do the Json encoding and sent to mobile app in yii framework?


Answer





A:



echo CJSON::encode($myArray);





A:



$criteria=new CDbCriteria;
$criteria->select='user_name'; // only select the 'user_name' column
$criteria->condition='user_id=:user_id';
$user_id = filter_input(INPUT_GET,'user_id');
if(FALSE===$user_id){

header($_SERVER['SERVER_PROTOCOL'].' 404 not found');
return false;
}

$criteria->params=array(':user_id'=>$user_id); // check
$user=Users::model()->find($criteria); // $params is not needed


//echo json as written at answer #1




Good luck!


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...