CJSON encode ignoring CActiveRecord getter

I have an AR class that includes the following virtual attribute getter function that returns a constructed url:

public function getUrl()


return $baseUrl . $this->id;


When I use CJSON to serialize an instance of my object:


The resulting json does not include my url attribute - is there a way to designate this virtual attribute as serializable by CJSON?

you can write a simple method to include that attribute something like this


// this goes in your model

public function toJson()


	array_push($this->attributes, $this->getUrl());

	return JSON::encode($this->attributes);


// then in your controller you can call

echo $myObject->toJson();