/** * Displays homepage. * * @return mixed */ public function actionIndex() { $Prod = new Product(); $Number_Of_Products = $Prod->getNumberOfProducts(); $max = $Number_Of_Products[0]["COUNT('product_id')"]; $Rand_Prod = array(); $numbers = range(1, $max); shuffle($numbers); if ($max >= 9) { foreach (range(0, 8) as $number) { array_push($Rand_Prod, $product = Product::find()->where(['product_id' => $numbers[$number]])->one()); } } else { throw new \yii\base\UserException("Add At Lease 9 Products to Database" . "\n" . "Products in Database : " . $max); } return $this->render('index', ['Rand' => $Rand_Prod]); }