$ultimaEncomenda=null;
$ultimaEncomenda=Encomenda::model()->findAllBySql(
"select * from encomenda where idencomenda=(select max(idencomenda) from encomenda where customer=:customer)",
array(":customer"=>Yii::app()->user->id));
$this->render('index',array('encomenda'=>$ultimaEncomenda));
Ok, I got it now. You need a finder method that returns a model instance. CActiveRecord::findBySql() does exactly that. The cause of the problem is the findAllBySql() method used in your code. It returns an array of objects.