Yii Framework and Android Application

10,133

Solution 1

Check out this: Yii REST API

Solution 2

You can use JSON / XML to communicate your android application with the php yii framework by building a simple REST API.

In order to do use the REST API this, you need to send HTTP request (Get / Post) from Android application. Then perform your operation based upon the request and send again in JSON formate using php json_encode or XML if you preferred.

You can also perform it using google Gson. it will help you to create JSON from java object.

Solution 3

Refer this: Simple API using Yii

I have done similar recently,

Yii side

you need custom controller sending json array and you can refer Yii REST API

public function actionTest()
{

    $commands = Command::model()->findAll();
    $cmdlist = array();

    if( $commands != '0'){
        foreach( $commands as $item ) 
        {
            $object = array();
            $object ['cmd'] = $item->command;
            $object ['command'] = $item->getCommandOptions($item->command);
            $object ['number'] = $item->number;
            $object ['id'] = $item->id;
            $cmdlist[] = $object;
        }
        $arr['command'] = $cmdlist;
    }

    header('Content-type: application/json');
    echo json_encode($arr);
    Yii::app()->end();
}

android side

You need a neat Async Http client with Json parser. I used android-async-http

Solution 4

I have an Android application that is on the market that I am switching to using the Yii framework. I use the http://www.yiiframework.com/extension/restfullyii/ extension. So far it's been great. I had a couple of issues with security and other things but overall the tool is what you will need. All you really care about for yii is having a restful API the rest of the logic should really be handled in your Android application. Also as a response type at this point I would only use json. I tried to implement a Android XML framework and decided to pull back because json did everything I needed to and was easy.

Share:
10,133
ashutosh
Author by

ashutosh

Updated on June 17, 2022

Comments

  • ashutosh
    ashutosh almost 2 years

    I like to raise some questions regrading Yii framework and Android applications. I am going to build a mobile application in Android platform and implementing Yii framework as server side. I like to know how much Yii framework supports Android platform? Are Yii framework web services fully compatible with Android?

    And, if can anyone suggest some tutorial or useful information, that will be very useful to me...

  • Hendy
    Hendy over 10 years
    i already build web CRUD with Yii, download and add android-async-http lib to my project libs folder, and follow your guide. i create table employee and add a function to send json array (like your code above). when i open mozilla, and add this link http://localhost/restayii/index.php/employee/getemployee it showing 5 employee json data, but i have an error on android side. if you don't mind, can you help me sir? you can see the detail in this post : stackoverflow.com/questions/19901272/…