/** * Finds the Ad model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Ad the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Ad::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function run() { $uploadPath = Yii::getAlias('@backend') . '/web/upload'; $model = Ad::findOne(['short_code' => $this->short_code]); if ($model && is_file($uploadPath . '/' . $model->pic_url)) { list($width, $height, $type, $attr) = getimagesize($uploadPath . '/' . $model->pic_url); if ($this->height && $this->width) { //nothing } elseif ($this->height) { $this->width = floor($this->height * $width / $height); } elseif ($this->width) { $this->height = floor($this->width * $height / $width); } $img = General::showImg($model->pic_url, 'c', $model->title, 'px', $this->width, $this->height); return $this->render('side-ad', ['model' => $model, 'img' => $img]); } else { return ''; } }