예제 #1
0
 public function actionIndex()
 {
     $model = new ExampleModel();
     echo '<br>';
     echo '<br>';
     echo '<br>';
     echo '<br>';
     echo '<br>';
     echo '<br>';
     dump($_REQUEST);
     //        $request = \Yii::$app->getRequest();
     //        if ($request->isPost && $request->post('ajax') !== null)
     //        {
     //            $model->load(\Yii::$app->request->post());
     //            app()->response->format = Response::FORMAT_JSON;
     //            $result = ActiveForm::validate($model);
     //            return $result;
     //        }
     if ($model->load(app()->request->post())) {
         if (!$model->validate()) {
             \Yii::error('Validation errors: ' . print_r($model->getErrors(), true));
         }
     }
     return $this->render('/test/test', ['model' => $model]);
 }
 public function run()
 {
     Yii::setAlias('@unclead-examples', realpath(__DIR__ . '/../'));
     $model = new ExampleModel();
     $request = Yii::$app->getRequest();
     if ($request->isPost && $request->post('ajax') !== null) {
         $model->load(Yii::$app->request->post());
         Yii::$app->response->format = Response::FORMAT_JSON;
         $result = ActiveForm::validate($model);
         return $result;
     }
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
     }
     return $this->controller->render('@unclead-examples/views/example.php', ['model' => $model]);
 }