Wednesday 8 May 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...