controllers/ApartmentController.php
/**
     * Creates a new Apartment model.
     * If creation is successful, the browser will be redirected to the 'view' page.
     * @return mixed
     */
Creates a new Apartment model.
If creation is successful, the browser will be redirected to the 'view' page.
@return mixed
Creates a new Apartment model . If creation is successful the browser will be redirected to the ' view ' page . @return mixed
public function actionCreate()
    {
        $model = new Apartment();
        $city = new City();
        $area = new Area();
        $street = new Street();
        $house_type = new HouseType();
        $my_functions = new MyFunctions();
        $all_cities = $city->getAllCities();
        $array_all_cities = $my_functions->myArray($all_cities, 'id', 'city');
        $all_areas = $area->getAllAreas();
        $array_all_areas = $my_functions->myArray($all_areas, 'id', 'area');
        $all_streets = $street->getAllStreets();
        $array_all_streets = $my_functions->myArray($all_streets, 'id', 'street');
        $all_house_types = $house_type->getAllHouseType();
        $array_all_house_types = $my_functions->myArray($all_house_types, 'id', 'type');
        $apartment_stage_complete = [1=>'строящийся', 2=>'каркас', 3=>'с ремонтом'];
        $apartment_payment = [1=>'наличка', 2=>'бартер', 3=>'гражданская ипотека', 4=>'военная ипотека', 5=>'материнский капитал'];
        $apartment_rights_house = [1=>'да', 2=>'нет', 3=>'в процессе'];
        $apartment_layout_type = [1=>'односторонняя', 2=>'разносторонняя', 3=>'сороконожка', 4=>'пентхаус', 5=>'студия'];
        $apartment_status = [1=>'активный', 2=>'продано'];
        $date = date('Y-m-d H:i:s');
        $apartment_post_array = Yii::$app->request->post();
        $_apartment_post_array = Yii::$app->request->post('Apartment');
        if(is_array($apartment_post_array) && !empty($apartment_post_array)){
            $_apartment_post_array['date_create'] = $date;
            $_apartment_post_array['date_update'] = null;
            $_apartment_post_array['user_id'] = 1;
            $_apartment_post_array['status'] = 1;
        }
        $apartment_post_array['Apartment'] = $_apartment_post_array;
        if ($model->load($apartment_post_array)) {
            if($model->save()){
                Yii::$app->session->setFlash('apartment_save_success', 'Данные успешно сохринились!');
                return $this->redirect(['update', 'id' => $model->id]);
            }else{
                Yii::$app->session->setFlash('apartment_save_failure', 'Данные не удалось сохринить!');
            }
        }else{
        }
        return $this->render('create', [
            'model' => $model,
            'array_all_cities' => $array_all_cities,
            'array_all_areas' => $array_all_areas,
            'array_all_streets' => $array_all_streets,
            'array_all_house_types' => $array_all_house_types,
            'apartment_stage_complete' => $apartment_stage_complete,
            'apartment_payment' => $apartment_payment,
            'apartment_rights_house' => $apartment_rights_house,
            'apartment_layout_type' => $apartment_layout_type,
        ]);
    }
public function actionCreate ( ) { $ model = new Apartment ( ) ; $ city = new City ( ) ; $ area = new Area ( ) ; $ street = new Street ( ) ; $ house_type = new HouseType ( ) ; $ my_functions = new MyFunctions ( ) ; $ all_cities = $ city -> getAllCities ( ) ; $ array_all_cities = $ my_functions -> myArray ( $ all_cities , 'id' , 'city' ) ; $ all_areas = $ area -> getAllAreas ( ) ; $ array_all_areas = $ my_functions -> myArray ( $ all_areas , 'id' , 'area' ) ; $ all_streets = $ street -> getAllStreets ( ) ; $ array_all_streets = $ my_functions -> myArray ( $ all_streets , 'id' , 'street' ) ; $ all_house_types = $ house_type -> getAllHouseType ( ) ; $ array_all_house_types = $ my_functions -> myArray ( $ all_house_types , 'id' , 'type' ) ; $ apartment_stage_complete = [ 1 => 'строящийся', 2=>'карк а ' ,  3=>'с ремонтом ' ; $ apartment_payment = [ 1 => 'наличка', 2=>'б а т ер ', 3=>'граждан с а я  ипотека', 4=>'военная ипотека', 5=>'мат е и нс кий капитал']; $ apartment_rights_house = [ 1 => 'да',  2 > 'н ет', 3=> ' пр оцессе']; $ apartment_layout_type = [ 1 => 'односторонняя', 2=>'разност о о нн яя', 3=>'сороконожка', 4=>'пен т а ус ', 5=>'студия']; $ apartment_status = [ 1 => 'активный', 2=>'пр о а но ']; $ date = date ( 'Y-m-d H:i:s' ) ; $ apartment_post_array = Yii :: $ app -> request -> post ( ) ; $ _apartment_post_array = Yii :: $ app -> request -> post ( 'Apartment' ) ; if ( is_array ( $ apartment_post_array ) && ! empty ( $ apartment_post_array ) ) { $ _apartment_post_array [ 'date_create' ] = $ date ; $ _apartment_post_array [ 'date_update' ] = null ; $ _apartment_post_array [ 'user_id' ] = 1 ; $ _apartment_post_array [ 'status' ] = 1 ; } $ apartment_post_array [ 'Apartment' ] = $ _apartment_post_array ; if ( $ model -> load ( $ apartment_post_array ) ) { if ( $ model -> save ( ) ) { Yii :: $ app -> session -> setFlash ( 'apartment_save_success' , 'Данные успешно сохринились!'); return $ this -> redirect ( [ 'update' , 'id' => $ model -> id ] ) ; } else { Yii :: $ app -> session -> setFlash ( 'apartment_save_failure' , 'Данные не удалось сохринить!'); } } else { } return $ this -> render ( 'create' , [ 'model' => $ model , 'array_all_cities' => $ array_all_cities , 'array_all_areas' => $ array_all_areas , 'array_all_streets' => $ array_all_streets , 'array_all_house_types' => $ array_all_house_types , 'apartment_stage_complete' => $ apartment_stage_complete , 'apartment_payment' => $ apartment_payment , 'apartment_rights_house' => $ apartment_rights_house , 'apartment_layout_type' => $ apartment_layout_type , ] ) ; }
Creates a new Apartment model.
Creates a new Apartment model .
//        print_r($apartment_post_array);echo"<br><ht><br>"; //        print_r($_apartment_post_array);echo"<br><ht><br>"; //        print_r($apartment_post_array); //        die(); //            Yii::$app->session->setFlash('apartment_saveload_failure', 'Данные не удалось получить!');