Skip to content

Instantly share code, notes, and snippets.

@jamband
Last active September 28, 2015 10:38
Show Gist options
  • Save jamband/1426123 to your computer and use it in GitHub Desktop.
Save jamband/1426123 to your computer and use it in GitHub Desktop.
<?php
class HogeController extends Controller
{
/**
* 単純な単一フィールド更新の例
*/
public function actionIsChecked($id)
{
Hoge::model()->updateByPk($id, array('checked' => 1);
...
}
/**
* 値を比較しての単一フィールド更新の例
*/
public function actionChangeFlag($id)
{
$model = Hoge::model()->findByPk($id);
if (!$model) {
throw new CHttpException(404, 'データがありません');
}
$model->is_deleted = $model->is_deleted !== '0' ? 0 : 1;
$model->update(array('is_deleted'));
// or $model->save(false, array('is_deleted'));
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment