public function run()
 {
     if (Yii::app()->request->isAjaxRequest && isset($_GET['q'])) {
         $title = Yii::app()->request->getParam('q', '');
         $limit = Yii::app()->request->getParam('limit', 50);
         $limit = min($limit, 50);
         $criteria = new CDbCriteria();
         $criteria->condition = "title LIKE :sterm";
         $criteria->params = array(":sterm" => "%{$title}%");
         $criteria->limit = $limit;
         $array = Workshop::model()->findAll($criteria);
         $result = '';
         foreach ($array as $val) {
             $result .= $val->getAttribute('title') . '|' . $val->getAttribute('id') . "\n";
         }
         echo $result;
     }
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Workshop::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 public function actionSignup($id)
 {
     if (isset($id)) {
         if (Yii::app()->request->isPostRequest) {
             /* @var $workshop Workshop */
             $workshop = Workshop::model()->findByPk($id);
             if ($workshop != null && $workshop->is_approved == 1) {
                 $studentWorkshop = new StudentWorkshop();
                 $studentWorkshop->user_id = Yii::app()->user->id;
                 $studentWorkshop->post_item_id = $id;
                 if ($studentWorkshop->save()) {
                     Yii::app()->user->setFlash('success', Yii::t('app', 'msg.success.workshop_signup'));
                     $this->redirect(array('view', 'id' => $id));
                 }
             } else {
                 throw new CHttpException(400, 'Event not found.');
             }
         } else {
             throw new CHttpException(400, 'Invalid Request');
         }
     } else {
         throw new CHttpException(400, 'Event not found.');
     }
 }