Is there an easy way to load one CActiveRecord?

Hi,

I’m new to yii and I wonder if there’s a way to do:

this:

$model = new User();

$model->first_name = ‘John’

$model->load()

print_r($model->attributes)

instead of:

$model = new User();

$cri = new Criteria()

$cri->condition = ‘first_name=:firstnamevar’;

$cri->params = array(’:firstnamevar’=>‘John’);

$modelData = $model->find($cri);

print_r($modelData->attributes)

Any advice would be helpful, thanks!

hey!

have you tried:




$model = User::model()->findByAttributes(array('first_name'=>'John'));



hope this helps!

regards!

:)

Hey scoob.junior,

Ahhh, I see. I think that’s what I need. I would hope there’d be a less-code method.

Thanks! :D