Exemplo n.º 1
0
 public function loadModel($id)
 {
     $model = Shop::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 2
0
 /**
  * Relations.
  *
  * @return array Relations.
  */
 public function relations()
 {
     return array('shop' => array(self::BELONGS_TO, Shop::model()->tableName(), 'shop_id'));
 }
Exemplo n.º 3
0
 public function actionShop()
 {
     $model = new Comment();
     // $criteria = new CDbCriteria();
     // $criteria->with = array ('user');
     $id = Yii::app()->request->getParam('id');
     // $commentlist = Comment::model()->findAllByAttributes(array('sid'=>$id),$criteria);
     $commentlist = Comment::model()->with('user')->findAllByAttributes(array('sid' => $id));
     $shop = Shop::model()->findByPk($id);
     if (isset($_POST['Comment'])) {
         $role = Yii::app()->user->getId();
         if (!empty($role)) {
             if (Yii::app()->user->roles != '0' && Yii::app()->user->roles != '1') {
                 $this->redirect(Yii::app()->createURL('site/login'));
             }
         } else {
             $this->redirect(Yii::app()->createURL('site/login'));
         }
         date_default_timezone_set('Asia/Shanghai');
         $model->postdate = date("Y-m-d H:i:s");
         $model->attributes = $_POST['Comment'];
         $model->sid = $id;
         $model->uid = Yii::app()->user->uid;
         if ($model->save()) {
             $this->redirect(Yii::app()->createURL('site/shop/id/' . $id));
         } else {
             print_r($model->getErrors());
             exit;
         }
     }
     $this->render('shop', array('model' => $model, 'commentlist' => $commentlist, 'shop' => $shop));
     // $this->render('test');
 }