Skip to content

Commit a406c5c

Browse files
committed
优化代码结构
1 parent 4a72a9c commit a406c5c

File tree

7 files changed

+332
-477
lines changed

7 files changed

+332
-477
lines changed

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+280-446
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+32-21
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,50 @@
1-
##四脚猫轻量级框架sijiaomao-mvc
2-
1+
四脚猫轻量级框架sijiaomao-mvc
2+
=======================================
33
- 基于composer的包管理器
4-
- 默认路由规则简单,controller/model/arg1/arg2...
5-
- 轻量级的ORM
6-
- 模版引擎强大而轻量
4+
- 路由规则灵活,可随意自定义路由规则
5+
- 包含默认路由:controller/model/arg1/arg2...
6+
- 轻量级的ORM ,轻松实现CRUD
7+
- 轻量而强大的模版引擎,安全过滤各种有...
78
- 配置文件就是PHP数组,基本无配置
89
- 数据库迁移采用migration,so easy!
910

1011

11-
## 基本使用
12-
- 安装
12+
基本使用
13+
---------------------------------
1314
1. git clone https://github.com/phpinside/mymvc.git mymvc
1415
2. 编辑 Apache下的httpd-vhost.conf文件,添加如下内容:
16+
1517
**注意以下的目录改成自己对应的本地目录!**
16-
<Directory "D:/demos/myMVC/app/web">
17-
Options Indexes FollowSymLinks Includes ExecCGI
18-
AllowOverride All
19-
Require all granted
20-
</Directory>
21-
22-
<VirtualHost *:80>
23-
ServerAdmin [email protected]
24-
DocumentRoot "D:/demos/myMVC/app/web"
25-
ServerName my.mvc.com
26-
ErrorLog "logs/my.mvc.com.com-error.log"
27-
CustomLog "logs/my.mvc.com-access.log" common
28-
</VirtualHost>
18+
19+
```apache
20+
21+
<Directory "D:/demos/myMVC/app/web">
22+
Options Indexes FollowSymLinks Includes ExecCGI
23+
AllowOverride All
24+
Require all granted
25+
</Directory>
26+
27+
<VirtualHost *:80>
28+
ServerAdmin [email protected]
29+
DocumentRoot "D:/demos/myMVC/app/web"
30+
ServerName my.mvc.com
31+
ErrorLog "logs/my.mvc.com.com-error.log"
32+
CustomLog "logs/my.mvc.com-access.log" common
33+
</VirtualHost>
34+
```
35+
2936
3. 启动Apache和MySQL
3037
4. 在MySQL中创建一个数据库mydb,用户名:mymvc, 密码:123456。
38+
当然了,如果本地已经有能用的数据库,那么可以去修改config/base.php中的配置即可。
39+
3140
**注意:mymvc这个用户需要有全部的数据库操作权限!**
41+
3242
5. 访问:http://my.mvc.com/home/migrate 执行初始化,生成todo数据表。
3343
6. 访问:http://my.mvc.com/todo/index 可以执行CRUD的各种操作。
3444
3545
36-
- 补充
46+
补充
47+
---------------------------------
3748
1. 系统自带默认路由,一般情况不需要去配置路由,自定义路由请查看config目录下的routes.php的示例。
3849
配置参考 <http://altorouter.com/usage/mapping-routes.html>
3950
2. 模版引擎参考 <https://latte.nette.org/>

app/config/routes.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
// map homepage
1515
$router->map('GET', '/', function () {
16-
17-
echo 'Hello';
16+
echo '<h1>'.date('Y-m-d H:i:s').' Hello, MyMVC ! ';
17+
echo '<br><a href="https://github.com/todo/index">去看看示例</a></h1>';
1818
});
1919

2020
// map users details page

app/controllers/BaseController.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@ public function initDb()
3131
public function initTpl()
3232
{
3333
$this->latte = new Engine();
34-
$this->latte->setTempDirectory(__DIR__ . '/../storage/views');
34+
$this->latte->setTempDirectory(APP_ROOT . '/storage/views');
3535
$set = new \Latte\Macros\MacroSet($this->latte->getCompiler());
3636
$set->addMacro('url', function ($node, $writer) {
3737
return $writer->write('echo "' . SITE_URL . '%node.args' . '"');
3838
});
39+
$this->latte->
3940
}
4041

4142
public function loadConfig()
4243
{
43-
$this->config = require __DIR__ . '/../config/base.php';
44+
$this->config = require APP_ROOT . '/config/base.php';
4445
}
4546

4647
public function render($name, array $params = [], $block = NULL)
4748
{
4849
$params['sitename'] = 'sijiaomao mvc framework';
49-
$tplFile = __DIR__ . '/../views/' . $name . '.latte';
50+
$tplFile = APP_ROOT . '/views/' . $name . '.latte';
5051
$this->latte->render($tplFile, $params, $block);
5152
}
5253

app/web/index.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
if (version_compare(PHP_VERSION, '5.6.0', '<')) die('require PHP > 5.6.0 !');
44

5-
define('SITE_URL','http://'.$_SERVER['HTTP_HOST'].substr($_SERVER['PHP_SELF'],0,-10) );
5+
define('APP_ROOT', dirname(__DIR__));
6+
define('SITE_URL', 'http://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['PHP_SELF'], 0, -10));
67

8+
date_default_timezone_set('Asia/Shanghai');
79

8-
require __DIR__ . '/../../vendor/autoload.php';
10+
11+
require APP_ROOT . '/../vendor/autoload.php';
912

1013

1114
$router = new AltoRouter();
1215

1316
// load map routes
14-
require __DIR__ . '/../config/routes.php';
17+
require APP_ROOT . '/config/routes.php';
1518
# to see http://altorouter.com/usage/processing-requests.html
1619
# to see https://github.com/dannyvankooten/AltoRouter
1720
# to compare with https://github.com/bramus/router
@@ -25,7 +28,7 @@
2528

2629
$router->map('GET|POST', '/[a:controllerName]/[a:actionName]/?[**:]', function ($controllerName, $actionName) {
2730
$args = explode('/', $_SERVER['REQUEST_URI']);
28-
$args = array_slice ( $args , 3 );
31+
$args = array_slice($args, 3);
2932
runAction($controllerName, $actionName, $args);
3033
});
3134

vendor/lox/pheasant/tests/Pheasant/Tests/DomainObjectTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testSavingUnknownProperty()
9999
// try non-saved objects
100100
$another = new Animal();
101101
$another->unknown;
102-
$instance->save();
102+
$another->save();
103103
}
104104

105105
public function testInitializeDefaults()

0 commit comments

Comments
 (0)