findAll Syntax:
<?php
$data = Test::model()->findAll('id=:id', array(':id' => (int) $_POST['id']));
foreach ($data as $row) {
echo "" . $row->attributes['id'] . "";
echo "" . $row->attributes['name'] . "";
}
?>
findAll with DropDownList Syntax:
<?php
echo $form->labelEx($model, 'test_id');
$list = CHtml::listData(Test::model()->findAll('is_active=1', array('order' => 'name')), 'test_id', 'name');
echo $form->dropDownList($model, 'test_id', $list, array('empty' => 'Select Test Type'));
echo $form->error($model, 'test_id');
?>
findAllByAttribute Syntax
<?php
$data = Test::model()->findAllByAttributes(array('name' => explode(",", $_POST['type'])));
foreach ($data as $row) {
//Your Statement
}
?>
updateByPk Syntax
<?php
$model = $this->loadModel($id);
Test::model()->updateByPk($model->id, array("is_active" => 0));
?>
deleteAll by id Syntax
<?php
Test::model()->deleteAll("id=".$_POST['id']);
?>
CDbCriteria Find() Condition (Syntax 1)
<?php
$criteria = new CDbCriteria;
$criteria->condition = 'user_id =1 AND status=1';
$folder = Test::model()->find($criteria);
?>
CDbCriteria Find() Condition (Syntax 2)
<?php
$email='test@example.com';
$criteria = new CDbCriteria;
$criteria->select = 'name';
$criteria->condition = 'id=:id OR email=:email';
$criteria->params = array(':id' => $_GET["id"], ':email' => $email);
$result = Test::model()->find($criteria);
?>
No comments:
Post a Comment