ActiveResource for the Yii PHP framework
Latest commit 9881e20 May 15, 2014 @Haensel Merge pull request #21 from wilwade/patch-1
Reset cURL to GET before setting the CustomRequest
Failed to load latest commit information.

EActiveResource for Yii an extension for the Yii PHP framework allowing the user to create models that use RESTful services as persistent storage. The implementation is inspired by Yii's CActiveRecord class ( and the Ruby on Rails implementation of ActiveResource (


CAUTION: THIS IS STILL AN ALPHA RELEASE! This project started as a draft and is still under development, so as long is there is no 1.0 release you may experience changes that could break your code. Look at the file for further information

As there are thousands of different REST services out there that use a thousand different approaches it can be tricky to debug errors. Because of that I added extensive tracing to all major functions, so you should always be able to see every request, which method it used and how the service responded. Just enable the tracing functionality of Yii and look for the category "ext.EActiveResource"


1.) Add the extension to Yii by placing it in your application's extension folder (for example '/protected/extensions') 2.) Edit your applications main.php config file and add 'application.extensions.EActiveResource.*' to your import definitions 3.) Add the configuration for your resources to the main config


4.) Now create a class extending EActiveResource like this (don't forget the model() function!):


     class Person extends EActiveResource
     /* The id that uniquely identifies a person. This attribute is not defined as a property      
      * because we don't want to send it back to the service like a name, surname or gender etc.
     public $id;

     public static function model($className=__CLASS__)
         return parent::model($className);

     public function rest()
         return CMap::mergeArray(

     /* Let's define some properties and their datatypes
     public function properties()
         return array(

     /* Define rules as usual */
     public function rules()
         return array(

     /* Add some custom labels for forms etc. */
     public function attributeLabels()
         return array(
             'name'=>'First name',
             'surname'=>'Last name',
             'salary'=>'Your monthly salary',


    /* sends GET to and populates a single Person model*/

    /* sends GET to and populates Person models with the response */

    /* create a resource
    $person=new Person;
    $person->name='A name';
    $person->save(); //New resource, send POST request. Returns false if the model doesn't validate

    /* Updating a resource (sending a PUT request)
    $person->name='Another name';
    $person->save(); //Not at new resource, update it. Returns false if the model doesn't validate

    //or short version
    Person::model()->updateById(1,array('name'=>'Another name'));

    /* DELETE a resource
    $person->destroy(); //DELETE to

    //or short version