how can use "findAllByAttributes"


(Amisam Sonpx) #1

I have code to find a row with a column that I knew the value:


 $userid = Yii::app()->user->id;

        

		$models=useremail::model()->findAllByAttributes('ue_userid',$userid);

        echo $models->ue_id;

but I have error mess:


Invalid argument supplied for foreach()

??? what wrong ?


(Amisam Sonpx) #2

I solved it :) I’m wrong with statement:

it must be:


     findByAttributes(array('username'=>$this->username));


(Namgivu) #3

Hi,

My favored usage is as below




$found = YourModelClass::model()->findAllByAttributes(

	array(),

	$condition  = 'columnNameInDb = :someVarName AND columnNameInDb02 > :someVarName02',

	$params     = array(

		':someVarName' => $someVarNameValue, 

		':someVarName02' => $someVarNameValue02,

	)

);



Hope it helps,

Nam.