/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Notecomment::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'noteId' => $this->noteId, 'userId' => $this->userId, 'createTime' => $this->createTime, 'parentId' => $this->parentId]); $query->andFilterWhere(['like', 'content', $this->content]); return $dataProvider; }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use app\models\Notecomment; use common\models\User; use yii\console\Markdown; /* @var $this yii\web\View */ /* @var $model app\models\Notecomment */ /* @var $form yii\widgets\ActiveForm */ if ($parId) { $username = Notecomment::getCommentByParId($parId); $huifu = '回复' . $username; } else { $huifu = ''; $parId = 0; $username = ''; } ?> <div class="notecomment-form"> <?php $form = ActiveForm::begin(['action' => ['/notecomment/create']]); ?> <?php echo $form->field($model, 'content')->textarea(['rows' => 6, 'placeholder' => $huifu]); ?> <?php
/** * Finds the Notecomment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Notecomment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Notecomment::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 根据主表Id显示笔记详情 * * @param * $id * @return Ambigous <string, string> */ public function actionViewnote($id) { $user = Notecomment::getCommentByParId(1); $get = Yii::$app->request->get(); if ($this->addScanNum($id)) { $mod = new Query(); $comment = $mod->select(['a.id', 'a.content', 'a.createTime', 'b.username'])->from('notecomment as a')->leftJoin('user as b', 'a.userId = b.id')->where(['noteId' => $id, 'parentId' => 0])->createCommand(); $renArr = ['model' => $this->findModel($id), 'comment' => $comment->queryAll(), 'tags' => $this->getHotTag(), 'hotnote' => $this->getHotAsk(3), 'commentMod' => new Notecomment(), 'parId' => isset($get['parId']) ? $get['parId'] : '']; return $this->render('viewnote', $renArr); } }