I have the following model:
<?php
/**
* Active record - CoreLang
*
*/
class CoreLang extends CActiveRecord
{
/**
* Table name property
*
* @var string
*/
public $tableName = 'core_lang';
/**
* Class constrcutor instance
*
* @param object $className
* @return object
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* Table name method
*
* @return string
*/
public function tableName()
{
return $this->tableName;
}
/**
* Relations between tables
*
* @return unknown
*/
public function relations()
{
return array(
'lang_id' => array(self::HAS_MANY, 'CoreLangWords', 'lang_id'),
);
}
public function onAfterFind($event)
{
return $event->sender->getAttributes();
}
/**
* Get core langs
*
* @param unknown_type $limit
* @return unknown
*/
public function all($limit=5)
{
$this->getDbCriteria()->mergeWith(array('limit' => $limit));
return $this;
}
}
I am calling it like so:
$lang = CoreLang::model()->all()->findAll();
print_r($lang);
It returns all the AR DB schema, relations etc… if you notice i added an event onAfterFind which returns an array of just the attributes returned.
If i do a print_r() for the $event->sender->getAttributes(); i get the following:
Array
(
[lang_id] => 1
[lang_locale] => en
[lang_short] => en_US
[lang_title] => English (USA)
[lang_currency_name] => USD
[lang_currency_symbol] => $
[lang_decimal] => .
[lang_comma] => ,
[lang_default] => 1
[lang_isrtl] => 0
)
Which is what i wanted, The thing is that i called the model by
$lang = CoreLang::model()->all()->findAll();
print_r($lang);
and the print_r above returns all the AR DB schema, relations and everything. How can i bypass that to return the array i built using the event onAfterFind ?
Thanks.