/** * Finds the Cuisine model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Cuisine the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Cuisine::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function behaviors() { return array_merge(parent::behaviors(), ['url' => ['class' => 'yii\\behaviors\\AttributeBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'guid', ActiveRecord::EVENT_BEFORE_UPDATE => 'guid'], 'value' => function ($event) { $url = ''; $estId = $this->Id; $estName = $this->urlFilter($this->name); $locality = Locality::findOne(['Id' => $this->localityId]); $estLocName = $locality->name; $estAdd1 = $this->address; $estLandmark = $this->landmark; if (isset($this->cuisines[0]['Id'])) { $cuisine = Cuisine::findOne(['Id' => $this->cuisines[0]['Id']]); } else { $cuisine = Cuisine::findOne(['Id' => $this->cuisines[0]]); } $estCuisineName = $cuisine->name; $estWhichTypeID = $this->entityType; $popLocName = ''; if ($estLocName != '') { $popLocName = $this->urlFilter($estLocName); } $estCityName = $this->urlFilter($this->cityname); if ($popLocName == "" && $estAdd1 != "") { $popLocName = $this->urlFilter(stripslashes($estAdd1)); } else { if ($popLocName == "" && $estAdd1 == "" && $estLandmark != "") { $popLocName = $this->urlFilter(stripslashes($estLandmark)); } } if ($popLocName == "") { $popLocName = "no-location"; } if ($estWhichTypeID == 1) { if (trim($estCuisineName) != '') { $popCusName = $this->urlFilter($estCuisineName) . "-"; } $url = '/' . $estCityName . '/' . $popLocName . '/' . $popCusName . 'restaurant-' . $estName . '/' . $estId; } else { $url = '/' . $estCityName . '/' . $popLocName . '/bar-' . $estName . '/' . $estId; } return $url; }], 'chainId' => ['class' => 'yii\\behaviors\\AttributeBehavior', 'attributes' => [ActiveRecord::EVENT_BEFORE_INSERT => 'chainId', ActiveRecord::EVENT_BEFORE_UPDATE => 'chainId'], 'value' => function ($event) { if ($this->chainId > 0) { return $this->chainId; } else { return 0; } }]]); }