/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Pictures::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'news_id' => $this->news_id, 'type_id' => $this->type_id, 'categories_id' => $this->categories_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'images', $this->images]); return $dataProvider; }
public function actionUpload() { $model = new UploadForm(); $pic = new Pictures(); $request = YII::$app->request; if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstance($model, 'file'); $name = time(); // //$url = Yii::$app->basePath."/web".'/'; if ($model->validate()) { $model->file->saveAs('../../Ontee/web/pictures/' . $name . '.' . $model->file->extension); $pic->url = 'pictures/' . $name . '.' . $model->file->extension; $pic->name = $model->file->baseName; $pic->type = $request->get('type'); $pic->save(); return $this->redirect(Url::to(['site/index', 'type' => $pic->type])); } } }
public function actionDelete() { $request = YII::$app->request->post(); $name = $request['name']; $sql = 'select * from pictures where name=:name'; $pic = Pictures::findBySql($sql, array(':name' => $name))->asArray()->one(); //删除pictures目录下的图片 $path = 'http://www.ontee.cn/' . $pic['url']; if (is_readable($path)) { unlink($path); } //删除数据库的记录 $connection = YII::$app->db; $model = $connection->createCommand('delete from pictures where name=:name'); $model->bindParam(':name', $name); if ($pic) { $model->execute(); } else { echo "Not Exists"; } echo "0"; }
<?php use app\models\Advert; use app\models\UploadForm; use yii\bootstrap\ActiveForm; use yii\bootstrap\Modal; use yii\bootstrap\Tabs; use yii\helpers\Html; use yii\bootstrap\Carousel; use app\models\Pictures; $this->title = 'Site/Index'; $imgModel = new UploadForm(); $id = 12; $pic = new Pictures(); echo '<pre>'; echo 'COOKIES: <br>'; print_r($_COOKIE); echo '</pre>'; //setcookie('views[11]', ""); ?> <div id="for-table"> <table style="max-width: 650px;"> <tr id="header-line" style="height: 50px; max-height: 50px;"> <td colspan="5" style="height: 50px; max-height: 50px; min-width: 400px;"> <div style="position: relative; margin-left: 20px; margin-top: 20px; max-height: 40px;"> <?php $form = ActiveForm::begin(['id' => 'add-picture', 'options' => ['enctype' => 'multipart/form-data']]); ?> <?php echo $form->field($imgModel, 'imageFile')->fileInput(['value' => 'choose', 'style' => 'opacity: 0; z-index: 3; position: relative;'])->label(false);
public function actionIndex() { return $this->render(['items' => \app\models\Pictures::query()->orderBy(['id' => SORT_DESC])->all()]); }
width: 154px; max-width: 154px; min-width: 154px; height: 190px; max-height: 190px; min-height: 190px; position: relative; margin-right: 5px; margin-bottom: 5px;'; $filename = 'img/page_3/3.png'; $style = 'background: url(img/page_3/4.png) no-repeat 50%; background-size: cover; width: 300px; height: 300px;'; $s = 'background-size: cover; width: 150px; height: 150px;'; Modal::begin(['size' => 'modal-lg', 'toggleButton' => ['label' => '', 'style' => $style, 'class' => 'carousel-but']]); Modal::end(); $pic = new Pictures(); ?> <div class="gallery" style="width: 70%; overflow: hidden; position: relative; display: block;"> <?php for ($i = 0; $i < 3; $i++) { ?> <div class="border" style="<?php echo $border; ?> "> <!-- <img src="<?php echo $pic->imgList(30)[$i]; ?> " style="max-width: 150px; max-height: 150px;" -->
public function actionUpload() { $model = new UploadForm(); $pic = new Pictures(); echo "1"; if (Yii::$app->request->isPost) { $model->file = UploadedFile::getInstance($model, 'file'); if ($model->validate()) { $Name = time(); $url = Yii::$app->basePath . "/web/img/"; $model->file->saveAs($url . $Name . '.' . $model->file->extension); $pic->url = '/img/' . $model->file->baseName . '.' . $model->file->extension; $pic->save(); } } echo "1"; }
/** * Finds the Pictures model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Pictures the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Pictures::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }