WHat I'm trying to do is set the quantity of tokens to 0 if there is no existing token amount in my database. However the code I ahve below doesn't work, although it's pretty much identical to what I use for buy and spend functions which work perfectly.
public function actionIndex() {
$_id = Yii::app()->user->getId();
$model = Tokens::model()->findByAttributes(array('UserID' => $_id));
if ($model === null)
$defaultqty = 0;
$model->TokenAmount = ($model->TokenAmount + $defaultqty);
$model->save(false);
throw new CHttpException(404, "yea it's broke, deal with it");
$this->render('index', array(
'model' => $model,
));
}