Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/.DS_Store
Binary file not shown.
Binary file added app/home/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions app/home/cache/cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"target_files":["index.php","userInfo.php"],"model_files":[{"name":".\/app\/home\/view\/index\/index.html","last_change":"2017-02-06 16:21:31"},{"name":".\/app\/home\/view\/user\/userInfo.html","last_change":"2017-02-15 10:57:12"}]}
13 changes: 13 additions & 0 deletions app/home/cache/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<?php for( $i = 0;$i < 2;$i++) {?>
<div style="width: 100px; height: 100px;background: red;">helo</div>
<?php } ?>
<script>console.log('我是js文件')</script>
</body>
</html>
1 change: 1 addition & 0 deletions app/home/cache/userInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>test userInfo</h1>
Binary file added app/home/controller/.DS_Store
Binary file not shown.
10 changes: 10 additions & 0 deletions app/home/controller/indexcontroller.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
class indexController extends conF{
public function index(){
$this->display();
}
public function lalala(){
$db = $this->D();
var_dump($db->select_by_sql('select * from user'));
}
}
10 changes: 10 additions & 0 deletions app/home/controller/usercontroller.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
class userController extends conF{
public function userInfo($name, $pass){

$this->display();
}
public function lalala(){
echo 'lalala';
}
}
2 changes: 2 additions & 0 deletions app/home/model/usermodel.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php

13 changes: 13 additions & 0 deletions app/home/view/index/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<each i = 0;i < 2;i++>
<div style="width: 100px; height: 100px;background: red;">helo</div>
</each>
<script src="app/home/view/js/index.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions app/home/view/js/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('我是js文件')
1 change: 1 addition & 0 deletions app/home/view/user/userInfo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<h1>test userInfo</h1>
26 changes: 26 additions & 0 deletions fream/conF.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
class conF{


public function display(){
$className = get_class($this);//获取当前控制器名
$class = new ReflectionClass($className);
$classPath = $class->getFileName();
preg_match("/\/app\/(.*?)\/controller/", $classPath,$result);
$module = $result[1];
$relName = preg_replace('/Controller/', '', $className);
$action = debug_backtrace()[1]['function'];
$viewFilePath = './app/'.$module.'/view/'.$relName.'/'.$action.'.html'; // 获取html模板的位置
$test = new parser(array($viewFilePath), $action.'.php', true); //模板引擎生成缓存文件
require_once('./app/'.$module.'/cache/'.$action.'.php');
}


public function D($host = 'localhost', $user = 'root', $password = '123456', $db_name='mactest'){
try{
return Mysql::get_instance($host, $user, $password, $db_name);
}catch(Exception $ex){
throw new Exception("数据链接字段有错", 1);
}
}
}
96 changes: 96 additions & 0 deletions fream/db.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
class Mysql{
private static $_instance = null;
private $db_name;
private $password;
private $usrname;
private $host;
private $connection = null;
/* 以下是数据库的链接 */



//链接数据库的参数以及保存实例的变量

private function __construct($host, $usrname, $password ,$db_name){
$this->db_name = $db_name;
$this->usrname = $usrname;
$this->password = $password;
$this->host = $host;
$this->conn();
}
//构造函数初始化变量

private function conn(){
$dsn = "mysql:host=$this->host;dbname=$this->db_name;charset=utf8";
if(!$this->connection = new PDO($dsn, $this->usrname, $this->password)){
trigger_error("数据库链接有误");
}
}
//数据库链接的方法在构造函数中调用

public function __clone(){
trigger_error("出现未知错误");
}
//防止克隆的方法

public static function get_instance($host, $usrname, $password ,$db_name){
if(!(self::$_instance instanceof self)){
self::$_instance = new self($host, $usrname, $password ,$db_name);
}else{
trigger_error("数据库已链接");
}
return self::$_instance;
}

/* 以下是增删改查的方法 */
public function _exec($sql){
$res = $this->connection->prepare($sql);
return $res->execute();
}

public function select_by_sql($sql){
$res = $this->connection->prepare($sql);
$lalala = $res->execute();
$result = $this->fich_all($res);
return $result;
}
//查询方法

public function add_by_sql($sql){
if($this->connection->exec($sql)){
return 1;
}else{
return 0;
}
}
//添加方法

public function delete_by_sql($sql){
if($this->connection->exec($sql)){
return 1;
}else{
return 0;
}
}
//删除方法

public function update_by_sql($sql){
$res = $this->connection->prepare($sql);
return $res->execute();
}
//更改方法

private function fich_all($res){
return $res->fetchAll(PDO::FETCH_ASSOC);
}
//分解查询后的数组方法

public function startsw(){
$this->connection->beginTransaction();
}
public function stopsw(){
$this->connection->commit();
}

}
Loading