public function actionIndex() { $searchModel = new DescriptionSearch(); //Problemi!!! It didn't work :( // $model = Description::findBySql('SELECT * FROM `description` AS a INNER JOIN `tag` AS b ON a.`tag`=b.`tag_id` ')->all(); // $model = Description::find()->join('INNER JOIN','tag','description.tag=tag.tag_id')->all(); $model = Description::find()->all(); $tag = Tag::find()->all(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['model' => $model, 'tag' => $tag]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Description::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(['desid' => $this->desid, 'date' => $this->date, 'tag' => $this->tag]); $query->andFilterWhere(['like', 'header', $this->header])->andFilterWhere(['like', 'art_body', $this->art_body])->andFilterWhere(['like', 'photo', $this->photo]); return $dataProvider; }
/** * Displays a single Items model. * @param integer $id * @return mixed */ public function actionView($id) { $commentsData = comment::getComments($id); $model = $this->findModel($id); $newComment = new Comment(); $addToBasket = new basket(); $description = new Description(); $description->find()->where(['item_id' => $id])->all(); $itemRating = ItemsRating::findOne($id); if ($model->count == 0) { Yii::$app->db->createCommand(" UPDATE `items` SET items.is_aviable=0 WHERE items.id =" . $id)->execute(); } else { if (!Yii::$app->user->isGuest) { $uid = Yii::$app->user->identity->getId(); $get_user = \dektrium\user\models\User::getUser($uid)->getModels()[0]['username']; if (isset($_POST['Comment'])) { // print_r($_POST['Comment']['text']); $newComment = new Comment(); $newComment->author = $get_user; $newComment->item_id = $id; $newComment->user_id = $uid; $newComment->date = date("Y-m-d h:i:s"); $newComment->text = $_POST['Comment']['text']; $newComment->save(); } if (isset($_POST['Basket'])) { if ($model->is_aviable) { if ($_POST['Basket']['count'] <= $model->count) { $addToBasket = new Basket(); $have = $addToBasket->find()->where(['item_id' => $id, 'user_id' => $uid])->all(); if (!$have) { $addToBasket->item_id = $id; $addToBasket->user_id = $uid; $addToBasket->name = $model->name; $addToBasket->price = $model->price; $addToBasket->count = $_POST['Basket']['count']; $addToBasket->sum = $model->price * $_POST['Basket']['count']; $addToBasket->save(); } } } return $this->redirect(['view', 'id' => $id]); } } } return $this->render('view', ['model' => $model, 'commentsData' => $commentsData, 'newComment' => $newComment, 'itemRating' => $itemRating, 'addToBasket' => $addToBasket, 'description' => $description]); }
public function joinDescTag() { $model = Description::find()->all(); var_dump($model); die; }