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…
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.
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…
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(
'select'=>'id',
'with'=>array('rapportEvaluation','professeur','etudiant','stageContext'),
// 'together'=>false,
));
if(isset($_GET['login_ece']))
$criteria->addSearchCondition('professeur.login_ece',$_GET['login_ece']);
$dataProvider=new CActiveDataProvider('Stage',array(
'criteria'=>$criteria,
'pagination'=>array(
'pageSize'=>5,
),
));
foreach ($dataProvider->getData() as $var)
$arr[] = array(
'id'=>$var->id,
'security_key'=>$var->rapportEvaluation->security_key,
'plagiat_percentage'=>$var->rapportEvaluation->plagiat_percentage,
'status'=>$var->rapportEvaluation->status,
'file_name'=>$var->rapportEvaluation->pdf_original,
'student_fullname'=>$var->etudiant->nom .' '. $var->etudiant->prenom,
'code'=>$var->stageContext->code,
);
echo CJSON::encode($arr);
Yii::app()->end();
}
Now I have two questions left:
Since I need to create each action twice for Web side and for Android. They use different url. Is there other solution?
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?
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” …
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.