Last active
September 28, 2015 10:38
-
-
Save jamband/1426123 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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