public function actionIndex() { //Get the wotd $wotd = AppConfig::findOne(1); $allWines = new Wines(); $currentDateTime = new \DateTime("now", new \DateTimeZone('America/Chicago')); $wotdDateTime = new \DateTime($wotd->wotd_dt, new \DateTimeZone('America/Chicago')); $diff = $currentDateTime->diff($wotdDateTime); if ($diff->days > 0) { $wineOfTheDay = $allWines->getRandomWine(Yii::$app->params['wotdMinRating']); $wotd->wotd_id = $wineOfTheDay->id; $wotd->wotd_dt = $currentDateTime->format('Y-m-d H:i:s'); $wotd->save(); } else { $wineOfTheDay = $allWines->findOne($wotd->wotd_id); if (!isset($wineOfTheDay)) { $wineOfTheDay = $allWines->getRandomWine(Yii::$app->params['wotdMinRating']); $wotd->wotd_id = $wineOfTheDay->id; $wotd->wotd_dt = $currentDateTime->format('Y-m-d H:i:s'); $wotd->save(); } } // renders the view file 'protected/views/site/index.php' // using the default layout 'protected/views/layouts/main.php' return $this->render('index', ['wineRecord' => $wineOfTheDay]); }