/** * Overload the construction so we can pull this items attributes * @param string $id */ public function __construct($id = NULL) { $this->id = $id; if ($id !== NULL) { $exists = Yii::app()->db->createCommand("SELECT uid FROM `cards` WHERE uid = :id")->bindParam(':id', $id)->queryScalar(); if ($exists === false) { throw new CHttpException(400, 'No card with that ID exists'); } } return parent::__construct(); }