예제 #1
0
 public function actionSearch()
 {
     $stateID = $_POST['state_id'];
     $cityID = $_POST['city_id'];
     if (isset($stateID) && isset($cityID) && $stateID != '' && $cityID != '') {
         //return $cityID;
         $model = \common\models\Address::find()->where(['state_id' => $stateID, 'city_id' => $cityID])->all();
     } else {
         if (isset($stateID) && $stateID != '') {
             $model = \common\models\Address::find()->where(['state_id' => $stateID])->all();
         } else {
             $model = \common\models\Address::find()->all();
         }
     }
     $html = '';
     foreach ($model as $adrs) {
         $university = University::findOne(['id' => $adrs->university_id]);
         $html .= '<li class="mason-item">
                 	<div class="box">
                     	<div class="img">
                         	<a href="' . \Yii::$app->urlManager->createUrl(['university/view', 'id' => $university->id]) . '"><img src="' . $university->logo . '" /></a>
                         </div>
                         <div class="text-block">
                         	<h3><a href="university-detail.html">' . $university->name . '</h3></a>
                             <span class="text-span redBg">' . $adrs->city['name'] . '</span>
                         </div>
                     </div>
             </li>';
     }
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return $html;
 }
예제 #2
0
 /**
  * Finds the University model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return University the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = University::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }