From 28a59a2fd58dd13a982cc63dfc9f3044c0c2b903 Mon Sep 17 00:00:00 2001 From: top_nuomi <1130395124@qq.com> Date: Thu, 5 Sep 2019 20:46:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=87=AA=E5=8A=A8=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=9A=84index=E6=A8=A1=E6=9D=BF=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E4=B8=BAIndex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + framework/create/create.php | 81 ++++++++++++++++++----- framework/create/tpl/controller/index.tpl | 6 +- framework/create/tpl/model/demo.tpl | 9 +-- 4 files changed, 71 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index a6b2bab..2acc497 100644 --- a/README.md +++ b/README.md @@ -973,6 +973,7 @@ $query 关闭数据库连接。 +#### 注意 Database类的事务与Model类不同,Model类进行了更进一步的封装。Database类事务使用示例: ``` use top\library\Database; diff --git a/framework/create/create.php b/framework/create/create.php index 99a3add..338dc5c 100644 --- a/framework/create/create.php +++ b/framework/create/create.php @@ -1,18 +1,46 @@ create(); } + /** + * 替换内容 + * @param $content + * @return mixed + */ public function replaceContent($content) { return str_replace([ @@ -38,9 +71,13 @@ class Create ], $content); } + /** + * 创建入口文件 + * @return bool + */ public function createStartFile() { - if ($this->start && !file_exists($this->start)) { + if ($this->start && !is_file($this->start)) { $content = file_get_contents($this->dir . 'tpl/index.tpl'); $content = $this->replaceContent($content); if (file_put_contents($this->start, $content)) { @@ -51,6 +88,9 @@ class Create return true; } + /** + * 创建配置文件 + */ public function createConfig() { $configPath = $this->projectPath . 'config/'; @@ -58,7 +98,7 @@ class Create if (!is_dir($configPath)) { mkdir($configPath, 0755, true); } - if (!file_exists($configFile)) { + if (!is_file($configFile)) { $content = file_get_contents($this->dir . 'tpl/config/config.tpl'); $content = $this->replaceContent($content); $realConfigFile = $this->base . '/' . $this->namespace . '/' . $this->name . '/config/config.php'; @@ -66,9 +106,11 @@ class Create exit('error -2'); } } - return true; } + /** + * 创建MVC目录及文件 + */ public function createMVC() { $dirArray = [ @@ -82,7 +124,7 @@ class Create } } $controllerFile = $this->projectPath . 'controller/index.php'; - if (!file_exists($controllerFile)) { + if (!is_file($controllerFile)) { $content = file_get_contents($this->dir . 'tpl/controller/index.tpl'); $content = $this->replaceContent($content); if (!file_put_contents($this->projectPath . 'controller/Index.php', $content)) { @@ -90,7 +132,7 @@ class Create } } $modelFile = $this->projectPath . 'model/demo.php'; - if (!file_exists($modelFile)) { + if (!is_file($modelFile)) { $content = file_get_contents($this->dir . 'tpl/model/demo.tpl'); $content = $this->replaceContent($content); if (!file_put_contents($this->projectPath . 'model/Demo.php', $content)) { @@ -98,10 +140,10 @@ class Create } } $viewFile = $this->projectPath . 'view/index/index.html'; - if (!file_exists($viewFile)) { + if (!is_file($viewFile)) { $content = file_get_contents($this->dir . 'tpl/view/index.tpl'); - if (!is_dir($this->projectPath . 'view/index/')) { - mkdir($this->projectPath . 'view/index/', 0755, true); + if (!is_dir($this->projectPath . 'view/Index/')) { + mkdir($this->projectPath . 'view/Index/', 0755, true); } if (!file_put_contents($this->projectPath . 'view/Index/index.html', $content)) { exit('error -6'); @@ -109,26 +151,35 @@ class Create } } + /** + * 创建函数库文件 + */ public function createFunctions() { $file = $this->projectPath . 'functions.php'; - if (!file_exists($file)) { + if (!is_file($file)) { if (!file_put_contents($file, "projectPath . '../route.php'; - if (!file_exists($file)) { + if (!is_file($file)) { if (!file_put_contents($file, file_get_contents($this->dir . 'tpl/route.tpl'))) { exit('-8'); } } } + /** + * 执行创建操作 + */ public function create() { $this->createStartFile(); diff --git a/framework/create/tpl/controller/index.tpl b/framework/create/tpl/controller/index.tpl index 216eb94..c595a95 100644 --- a/framework/create/tpl/controller/index.tpl +++ b/framework/create/tpl/controller/index.tpl @@ -2,14 +2,14 @@ namespace app\{name}\controller; -use top\library\Controller; +use app\{name}\model\Demo; -class Index extends Controller +class Index { public function index() { - $model = model(\app\{name}\model\Demo::class); + $model = model(Demo::class); return [ 'hello' => $model->get() ]; diff --git a/framework/create/tpl/model/demo.tpl b/framework/create/tpl/model/demo.tpl index 7c1e7f1..3e1c316 100644 --- a/framework/create/tpl/model/demo.tpl +++ b/framework/create/tpl/model/demo.tpl @@ -2,15 +2,8 @@ namespace app\{name}\model; -use top\library\Model; - -class Demo extends Model +class Demo { - - protected $table = ''; - protected $pk = ''; - protected $map = []; - public function get() { return '模块{name}正在运行...';