To display all the data in a model,Using findAll function is one of the easiest way of doing it.
first we will assign findAll() in a variable.
$User = user::model()->findAll();
$User is now an array, we will now loop our variable and display the content.
$User = user::model()->findAll();
foreach($User as $row){
echo 'username -' . $row;
}
We can also add sorting by just adding
'order'=>'id'
note: you can change the 'id' to a different field that you want to sort
Now, Inert the code to findAll() to add sorting and thats it.
$User = user::model()->findAll(array('order'=>'id DESC'));
foreach($User as $row){
echo 'username -' . $row;
}
No comments:
Post a Comment