I am creating project in Yii framework. In controller i have function as-
public function actiongetCuriosityQuestionAnswer()
{
$model=new Curiosityquestion;
$json='{"questionId":1}';
$obj=json_decode($json);
$model->questionId=$obj->questionId;
$record=Curiosityquestion::model()->findByPk($model->questionId);
echo "The Question=".$record->question."</br>"."Its answer is-".$record->answer;
echo CJSON::encode($record->answer,$record->question);
}
I want to send question and answer in json format. But “CJSON::encode($record->answer,$record->question);” is sending only answer in json format. i.e. CJSON::_encode is accepting only one parameter. So how to send both question and option in json format together?
Pass your whole object to CJSON::encode, e.g.:
If you want specific elements, pass as an an array, e.g.:
In your javascript, you can access the elements as javascript objects, e.g.
data['answer']or something similar