├── readme.txt
└── mvc
├── view
└── index
│ └── index.php
├── index.php
├── config
└── config.php
├── controller
└── index.php
├── help
└── function.php
└── lib
├── db
└── db.php
└── AutoLoader.class.php
/readme.txt:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mvc/view/index/index.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 | Document
9 |
10 |
11 | = $contents ?>
12 |
13 |
--------------------------------------------------------------------------------
/mvc/index.php:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/mvc/config/config.php:
--------------------------------------------------------------------------------
1 | 'Index',
16 | //默认访问方法
17 | 'DefaultAction'=>'index',
18 | //数据库地址
19 | 'host'=>'127.0.0.1',
20 | //数据库
21 | 'dbname'=>'eleven',
22 | //数据库用户名
23 | 'username'=>'root',
24 | //数据库密码
25 | 'password'=>'root',
26 | //数据库编码
27 | 'charset'=>'utf8',
28 | //调试模式
29 | 'DeBug'=>true,
30 | //自定义方法
31 | 'HELP'=>
32 | [
33 | 'function',
34 | ]
35 | ];
--------------------------------------------------------------------------------
/mvc/controller/index.php:
--------------------------------------------------------------------------------
1 | select($sql);
22 | // var_dump($data);
23 | // $data=C();
24 | // print_r($data);die;
25 | view('index/index',['contents'=>'2222']);
26 | //view('index');
27 | echo "默认访问路径";
28 | }
29 | public function test()
30 | {
31 | echo "这不是默认访问路径";
32 | }
33 | }
34 |
35 |
--------------------------------------------------------------------------------
/mvc/help/function.php:
--------------------------------------------------------------------------------
1 | 视图层文件不存在:$VIEW_FILE");
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/mvc/lib/db/db.php:
--------------------------------------------------------------------------------
1 | getMessage());die;
27 | }
28 | //再次设置数据库编码
29 | $this->exec("set names {$CONFIG['charset']}");
30 | }
31 |
32 | public function add($sql)
33 | {
34 | $MYSQL = $this->exec($sql);
35 | if($MYSQL)
36 | {
37 | return $this->lastInsertId();
38 | }else
39 | {
40 | return false;
41 | }
42 | }
43 | public function del($sql)
44 | {
45 | $MYSQL = $this->exec($sql);
46 | if($MYSQL)
47 | {
48 | return $this->lastInsertId();
49 | }else
50 | {
51 | return false;
52 | }
53 | }
54 | public function save($sql)
55 | {
56 | $MYSQL = $this->exec($sql);
57 | if($MYSQL)
58 | {
59 | return $this->lastInsertId();
60 | }else
61 | {
62 | return false;
63 | }
64 | }
65 | public function select($sql)
66 | {
67 | $MYSQL = $this->query($sql);
68 | if($MYSQL)
69 | {
70 | return $MYSQL->fetchAll(\PDO::FETCH_ASSOC);
71 | }else
72 | {
73 | return false;
74 | }
75 | }
76 |
77 | }
78 |
--------------------------------------------------------------------------------
/mvc/lib/AutoLoader.class.php:
--------------------------------------------------------------------------------
1 | config = $config;
22 | spl_autoload_register(array($this,"load"));
23 | //调用报错机制
24 | // $this->DeBug();
25 | //加载自定义方法
26 | $this->HELP();
27 | $this->Route();
28 | // new db();
29 | }
30 | //路由方法
31 | protected function Route()
32 | {
33 | //接收访问路径中的参数
34 | $route=trim(isset($_GET['r'])?$_GET['r']:'/');
35 | unset($_GET['r']);//?
36 | // var_dump($_GET);
37 | $new_route= explode('/',$route);
38 | //var_dump($new_route);
39 | //判断控制器和方法
40 | $Controller='controller\\'.strtolower(empty($new_route[0])?$this->config['DefaultController']:$new_route[0]);
41 | $action=isset($new_route[1])?$new_route[1]:$this->config['DefaultAction'];
42 | (new $Controller)->$action();
43 | }
44 |
45 | //加载自定义方法
46 | protected function HELP()
47 | {
48 | foreach($this->config['HELP'] as $v)
49 | {
50 | //加载自定义函数库
51 | include_once APP_PATH.DS.'help/'.$v.'.php';
52 | }
53 | }
54 | //封装加载函数
55 | public function load($class)
56 | {
57 | if(in_array($class,$this->parameter))
58 | {
59 | return true;
60 | }
61 | else
62 | {
63 | //把命名空间转换成目录,加载出来
64 | $className=str_replace("\\",DS,$class).'.php';
65 | // echo $className;
66 | $class_Data=explode('\\',$className);
67 | //var_dump($class_Data) ;
68 | //根据命名空间判断一下加载的哪个模块下的哪个类
69 | $loadfile=APP_PATH.DS.$className;
70 | //echo $loadfile;
71 | if(isset($loadfile))
72 | {
73 | if(is_file($loadfile))
74 | {
75 | include_once $loadfile;
76 | $this->parameter[$class]=$class;
77 | }
78 | else
79 | {
80 | return false;
81 | }
82 | }
83 |
84 | }
85 | //$className 形参 //命名空间 use 后边的的东西
86 |
87 |
88 | }
89 | }
90 |
91 |
--------------------------------------------------------------------------------