/** * Creates a new Entity model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Entity(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function add($file, $path) { // var_dump($file);die(); $folder = $this->entity($path); $new = new Entity(['ownerid' => \Yii::$app->user->id, 'type' => $file->type, 'name' => $file->name, 'parentid' => $folder->id, 'entityid' => $file->id, 'path' => $folder->path . $file->name, 'size' => $file->size, 'sizefull' => $file->sizefull, 'mimetype' => $file->mimetype]); $i = 0; while ($this->entity($new->path)) { $i++; $new->path = $folder->path . $file->name . '_' . $i; } if ($i) { $new->name .= '_' . $i; } if (!$new->save()) { var_dump($new->errors); } return ['Path' => $folder->path, 'Name' => $new->name, 'Error' => '', 'Code' => 0]; }