Skip to content

Instantly share code, notes, and snippets.

@elderdosantos
Created December 3, 2014 13:02
Show Gist options
  • Save elderdosantos/2b9e1812e7676238e7c0 to your computer and use it in GitHub Desktop.
Save elderdosantos/2b9e1812e7676238e7c0 to your computer and use it in GitHub Desktop.
Yii: CDbCriteria with Yii::app()->db->createCommand()
<?php
/**
* To use CDbCriteria with createCommand follow this tip:
*/
$criteria = new CDbCriteria();
$criteria->compare('id', $this->id);
$criteria->addCondition('user.id in (select userid from user_groups where group_type = 1');
$command = Yii::app()->db->createCommand();
$command->from('vci_veiculo');
$command->andWhere($criteria->condition, $criteria->params);
$results = $command->queryAll();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment