예제 #1
0
 public function store($properties = [])
 {
     // Create and save a new object
     $object = new Object($properties);
     $object->save();
     return $object;
 }
예제 #2
0
 /**
  * Creates a new Object model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Object();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #3
0
 public function beforeSave($insert)
 {
     if ($insert) {
         $object = new Object();
         $object->type = $this->getType();
         $object->user_id = Yii::$app->user->id;
         $object->name = $this->name;
         if (!$object->save()) {
             throw new Exception('Не удалось создать запись в таблице объектов');
         }
         $this->id = $object->id;
     } else {
         $this->object->name = $this->name;
         if (!$this->object->save()) {
             throw new Exception('Не удалось сохранить запись в таблице объектов');
         }
     }
     return parent::beforeSave($insert);
 }
예제 #4
0
 /**
  * Creates a new Object model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreateobject()
 {
     if (!\Yii::$app->user->isGuest) {
         $modelobject = new Object();
         $arrayuser = array();
         if (Yii::$app->user->identity->role == 10) {
             $modelsuser = Users::find()->where(['role' => 1])->select(['id', 'username'])->all();
         }
         if (Yii::$app->user->identity->role == 5) {
             $modelsuser = Users::find()->where(['role' => 1, 'id_manager' => Yii::$app->user->identity->id])->select(['id', 'username'])->all();
         }
         if ($modelsuser != NULL) {
             foreach ($modelsuser as $modeluser) {
                 $arrayuser[$modeluser->id] = $modeluser->username;
             }
         }
         //default user id
         $modelobject->id_user = Yii::$app->user->identity->id;
         //default user id
         if ($modelobject->load(Yii::$app->request->post())) {
             //$modelobject->id_user = Yii::$app->user->identity->id;
             if ($modelobject->save()) {
                 Yii::$app->session->setFlash('info', 'Заведение создано.');
                 return $this->redirect(['object', 'id' => $modelobject->id]);
             } else {
                 Yii::$app->session->setFlash('error', 'Заведение не создано.');
                 return $this->refresh();
             }
         } else {
             return $this->render('createobject', ['model' => $modelobject, 'arrayuser' => $arrayuser]);
         }
     } else {
         return $this->redirect(['login']);
     }
 }