diff --git a/controllers/CollectionController.php b/controllers/CollectionController.php index 9177941..6e97792 100644 --- a/controllers/CollectionController.php +++ b/controllers/CollectionController.php @@ -4,6 +4,7 @@ namespace app\controllers; use app\models\CollectionTasks; use app\models\CollectionSearch; +use Yii; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; @@ -68,10 +69,14 @@ class CollectionController extends Controller public function actionCreate() { $model = new CollectionTasks(); + $model->scenario = 'create'; // 设置场景 if ($this->request->isPost) { - if ($model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); + if ($model->load($this->request->post())) { + $model->user_id = Yii::$app->user->id; // 手动设置user_id字段的值 + if ($model->save()) { + return $this->redirect(['view', 'id' => $model->id]); + } } } else { $model->loadDefaultValues(); @@ -82,26 +87,6 @@ class CollectionController extends Controller ]); } - /** - * Updates an existing CollectionTasks model. - * If update is successful, the browser will be redirected to the 'view' page. - * @param int $id ID - * @return string|\yii\web\Response - * @throws NotFoundHttpException if the model cannot be found - */ - public function actionUpdate($id) - { - $model = $this->findModel($id); - - if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { - return $this->redirect(['view', 'id' => $model->id]); - } - - return $this->render('update', [ - 'model' => $model, - ]); - } - /** * Deletes an existing CollectionTasks model. * If deletion is successful, the browser will be redirected to the 'index' page. diff --git a/models/CollectionTasks.php b/models/CollectionTasks.php index 5ed1949..9996a46 100644 --- a/models/CollectionTasks.php +++ b/models/CollectionTasks.php @@ -3,6 +3,7 @@ namespace app\models; use Yii; +use yii\db\ActiveRecord; /** * This is the model class for table "collection_tasks". @@ -16,8 +17,10 @@ use Yii; * @property CollectionUploaded[] $collectionUploadeds * @property User $user */ -class CollectionTasks extends \yii\db\ActiveRecord +class CollectionTasks extends ActiveRecord { + const SCENARIO_CREATE = 'create'; + /** * {@inheritdoc} */ @@ -33,6 +36,7 @@ class CollectionTasks extends \yii\db\ActiveRecord { return [ [['user_id', 'folder_path', 'secret'], 'required'], + [['folder_path', 'secret'], 'required', 'on' => self::SCENARIO_CREATE], [['user_id'], 'integer'], [['created_at'], 'safe'], [['folder_path', 'secret'], 'string', 'max' => 255], @@ -54,6 +58,16 @@ class CollectionTasks extends \yii\db\ActiveRecord ]; } + /** + * {@inheritdoc} + */ + public function scenarios() + { + $scenarios = parent::scenarios(); + $scenarios[self::SCENARIO_CREATE] = ['folder_path', 'secret']; // 在这里列出你想在创建收集任务时验证的属性 + return $scenarios; + } + /** * Gets query for [[CollectionUploadeds]]. * diff --git a/views/collection/_form.php b/views/collection/_form.php deleted file mode 100644 index e7497f1..0000000 --- a/views/collection/_form.php +++ /dev/null @@ -1,29 +0,0 @@ - - -
- = Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?> - = Html::a('Delete', ['delete', 'id' => $model->id], [ + = Html::a('复制收集链接', null, ['class' => 'btn btn-primary', 'id' => 'copy-link-button']) ?> + = Html::a('访问收集链接', ['collection/access', 'id' => $model->id, '$secret' => $model->secret], ['class' => 'btn btn-primary', 'target' => '_blank']) ?> + = Html::a('取消收集', ['delete', 'id' => $model->id], [ 'class' => 'btn btn-danger', 'data' => [ - 'confirm' => 'Are you sure you want to delete this item?', + 'confirm' => '你确定要取消这个收集任务吗?已收集的文件不会被删除', 'method' => 'post', ], ]) ?> @@ -37,14 +40,13 @@ $dataProvider->query->andWhere(['task_id' => $model->id]); 'model' => $model, 'attributes' => [ 'id', - 'user_id', 'folder_path', 'created_at', 'secret', ], ]) ?> -