Ejemplo n.º 1
0
 public function actionGet($thread)
 {
     $model = new Comment();
     if (!$model->setThread($thread)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $comments = Comment::find()->comments($model->module, $model->itemid)->all();
     $ret = ['comments' => []];
     foreach ($comments as $c) {
         $ret['comments'][] = $c->asArray();
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     $ret['count'] = sizeof($ret['comments']);
     echo json_encode($ret);
 }
Ejemplo n.º 2
0
 /** @inheritdoc */
 public function run()
 {
     $model = new Comment();
     /*if ($this->validate && $model->load(\Yii::$app->request->post()) && $model->login()) {
                 return \Yii::$app->response->redirect(\Yii::$app->user->returnUrl);
             }
     */
     if (!$model->setThread($this->module, $this->itemid)) {
         throw new InvalidConfigException("Module or ItemID unexpected (" . $this->module . '/' . $this->itemid . "). Allows only [0-9a-zA-Z_].");
     }
     $comments = Comment::find()->comments($this->module, $this->itemid)->count();
     $this->registerClientScript();
     $view = $this->getView();
     $view->registerJs("jQuery('#threads-comments-{$model->thread}').threads();");
     $coms = [['time' => '123', 'text' => '234'], ['time' => '1asdasd23', 'text' => 'qweqweqw']];
     //$view->registerJs("$('#commentTemplate').tmpl(".json_encode($coms).").appendTo('#commentList');");
     //$this->action['thread']=$model->getThread();
     return $this->render('comments', ['model' => $model, 'comments' => $comments, 'action' => \yii\helpers\Url::to($this->action)]);
 }