public function actionIndex() { // $pictures = Pictures::find()->all(); $request = YII::$app->request; $type = $request->get('type', 0); $sql = 'select * from pictures where type=:type'; $pictures = Pictures::findBySql($sql, array(':type' => $type))->all(); return $this->render('index', ['pictures' => $pictures]); }
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"; }