php - Yii2 only display data where posted on date is less than or equal to current datetime -


i have field within database called publish_on_date store date post should become active.

now unsure on how add query dataprovider/search model.

so need add query query display date , check if less or equal (now being current date/server date).

here current search functon

    public function search($params, $pagesize = 3, $published = false) {     $query = article::find();      // means editor trying see articles     // allow him see published ones , drafts made him     if ($published === true)      {         $query->where(['status' => article::status_published]);         $query->orwhere(['user_id' => yii::$app->user->id]);     }      $dataprovider = new activedataprovider([         'query' => $query,         'sort'=> ['defaultorder' => ['id' => sort_desc]],         'pagination' => [             'pagesize' => $pagesize,         ]     ]);      if (!($this->load($params) && $this->validate())) {         return $dataprovider;     }      $query->andfilterwhere([         'id' => $this->id,         'user_id' => $this->user_id,         'status' => $this->status,         'category' => $this->category,     ]);      $query->andfilterwhere(['like', 'title', $this->title])         ->andfilterwhere(['like', 'summary', $this->summary])         ->andfilterwhere(['like', 'content', $this->content]);      return $dataprovider; } 

just add someplace condition

$query->andwhere('publish_on_date <= now()'); 

you can add when first create query

$query = article::find()->andwhere('publish_on_date <= now()'); 

or later down page


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -