Android Client App with Yii Framework

Hi all,

I am going to write a system with Web Server and Android Client side.

For the server side, I would like to choose Yii or Symfony to implement it. And users can do simple login/logout CRUD.

For the client side, I will create a Android App to get those informations. That should be a pure Android Application.

For the communication, I want to use RESTful JSON format for the data exchanging.

Anyone has any idea about how to connect between Android App and Yii server? Now, I could get a HTML page from server and display it in Android… But I want JSON JSON…

Best wishes and Thank you all


Have you looked in to Yii WebServices? It supports SOAP fairly well, you can use the WSDL to generate your java classes for sending messages back and forth.

Look at this basic approach. You see, it’s very easy to create a JSON response. You’re not obliged to call render() in a controller action.

public function actionUser() 


    // missing some sanity checks...

    $id=isset($_GET['id']) ? (int) $_GET['id'] : null;


    echo json_encode($user->getAttributes());


Thank you very much. However, as I have mentioned, I would like to use RESTful & JSON instead of SOAP… I think SOAP is heavy. Anyway, thanks a lot. I have 2 days left to figure it out. If I can’t find the solution. I have to use SOAP…


thanks a lot. Mike,

I think I understand your approach. My question is where should I call this method if I create this kind of code in the controller. Maybe my problem is I don’t understand the Yii work flow clearly. I need to keep the original View code because there’s user interface in the web side. Meanwhile, I would like this server provides interface for Android App by POST/GET url. Similar like twitter API…


when you set your action up have it echo your JSON (if you choose to go that route), then you can just call that url from your java code to get the content.

Thank you DarkNSF. And I have solved that problem by that solution. I create an action in the controller and echo the JSON code.


	 * Lists all reports general info based on the professor login_ece, in json format.


	public function actionRapportList()


		$criteria=new CDbCriteria(array(



//			'together'=>false,




		$dataProvider=new CActiveDataProvider('Stage',array(






		foreach ($dataProvider->getData() as $var)

			$arr[] = array(






				'student_fullname'=>$var->etudiant->nom .' '. $var->etudiant->prenom,



		echo CJSON::encode($arr);



Now I have two questions left:

  1. Since I need to create each action twice for Web side and for Android. They use different url. Is there other solution?

  2. As in the code, I use ActiveDataProvider and get the “Stage” object. But I can’t find a way to get the ONLY columns I need… So I have to use a loop and select the columns in each data. Is that possible to do that select job in the provider?

I don’t understand what you mean? Are you saying the request is using multiple controllers?

It should look something like the following. The value ‘t’ is self referential to the model ‘Stage’, I believe.



		$criteria=new CDbCriteria(array(

			'select'=>', rapportEvaluation.security_key, rapportEvaluation.plagiat_percentage,rapportEvaluation.status,rapportEvaluation.pdf_original,etudiant.nom,etudiant.prénom,stageContext.code',




Hi Thank you backwardselvis,

For the second question, I tested your solution and it doesn’t work. The CDbException shows Active record “Stage” is trying to select an invalid column “rapportEvaluation.security_key” …

I read another topic about the eager loading in CJSON::encode. Maybe that’s the problem.

For the first question, yes. I was saying for the same function I need two controller/actionA and controller/actionB for web site and Android. I was wondering if there is any other ways.