更新readme文件、删除多余文件
This commit is contained in:
parent
278843d6ba
commit
4e70ddd22d
845
README.md
845
README.md
|
@ -1 +1,844 @@
|
|||
### TOP-Framework
|
||||
# TOP-Framework
|
||||
*这是一个部分代码源自三年前毕业设计中的代码集合,后经过一系列重构,形成的一套框架。在此准备写一个文档。*
|
||||
|
||||
## 模块
|
||||
### 创建模块
|
||||
1. 手动创建
|
||||
在application(可更改)目录下创建home目录,再创建config、controller(必须)、model、view目录
|
||||
2. 命令行自动创建
|
||||
命令格式([]为可选参数):
|
||||
```
|
||||
php create.php 目录 模块名 [入口文件]
|
||||
```
|
||||
|
||||
进入framework/create/目录,执行以下命令:
|
||||
```
|
||||
php create.php application home index
|
||||
```
|
||||
|
||||
至此,已经通过简单的命令创建了home模块,浏览器输入127.0.0.1即可访问home模块(系统默认模块为home模块,可在入口文件中指定),亦可命令行访问home模块。
|
||||
|
||||
## 控制器
|
||||
### 创建控制器
|
||||
一个典型的控制器(Index.php)
|
||||
```
|
||||
<?php
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
class Index
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
```
|
||||
其中包括了命名空间、以及一个默认的index方法,index方法返回数组或布尔值true则会显示模板,如果返回的是数字或字符串则会直接输出,返回对象直接输出[OBJECT],关于模板部分后面会详细介绍。
|
||||
|
||||
如果当前控制器继承自top\library\Controller基础控制器,则会继承以下方法:
|
||||
1. json($msg, $code = 1, $data = [], $ext = [])
|
||||
|
||||
返回json数据。
|
||||
|
||||
2. cache($status = true)
|
||||
|
||||
如果在方法中调用了此方法则会将模板做静态缓存,缓存时间在配置文件中设置。
|
||||
|
||||
3. param($name, $value)
|
||||
|
||||
将参数传递到模板文件。
|
||||
|
||||
4. view($file = '', $param = [], $cache = false)
|
||||
|
||||
显示模板(得到模板文件渲染后的内容)。
|
||||
|
||||
5. redirect($url)
|
||||
|
||||
利用header函数跳转。
|
||||
|
||||
6. tips($message, $url = '', $sec = 3)
|
||||
|
||||
如果是AJAX请求则会返回json数据(调用json方法),普通请求则返回tips模板文件渲染后的内容。
|
||||
### 展示模板
|
||||
```
|
||||
public function index()
|
||||
{
|
||||
return $this->view();
|
||||
}
|
||||
```
|
||||
调用基础控制器中的view方法、并return出去,完成模板的展示。
|
||||
### 模板传值
|
||||
1. view方法
|
||||
```
|
||||
public function index()
|
||||
{
|
||||
return $this->view(null, [
|
||||
'param' => 'Hello world!'
|
||||
]);
|
||||
}
|
||||
```
|
||||
2. 直接return数组
|
||||
```
|
||||
public function index()
|
||||
{
|
||||
return [
|
||||
'param' => 'Hello world!'
|
||||
];
|
||||
}
|
||||
```
|
||||
以上两种方式等效。
|
||||
### 控制器方法的前置、后置操作
|
||||
```
|
||||
public function before_index()
|
||||
{
|
||||
}
|
||||
|
||||
public function after_index()
|
||||
{
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
return [
|
||||
'param' => 'Hello world!'
|
||||
];
|
||||
}
|
||||
```
|
||||
命名规范:before_方法名(前置)、after_方法名(后置),执行index方法之前会先执行before_index方法(如果存在),执行完index方法后会执行after_index方法(如果存在)。当前置方法return的值为空字符串、null、true时才会继续执行,否则前置方法的return等效于index方法的return。
|
||||
|
||||
## 模型
|
||||
### 创建模型
|
||||
一个典型的模型(Users.php)
|
||||
```
|
||||
<?php
|
||||
|
||||
namespace app\home\model;
|
||||
|
||||
use top\library\Model;
|
||||
|
||||
class 模型名称 extends Model
|
||||
{
|
||||
}
|
||||
```
|
||||
系统会根据模型名称去绑定对应同名称的数据表,例:模型名称为Users时,则绑定名为”前缀_users“的数据表。如果模型名称为UsersInfo时,则绑定名为“前缀_users_info”的数据表。
|
||||
|
||||
继承自top\library\Model基础模型后,模型将拥有以下方法或属性:
|
||||
#### 方法:
|
||||
1. data($data = [], $notRaw = true)
|
||||
获取即将操作的数据
|
||||
|
||||
接收两个参数,参数一:指定的数据(数组),传入空数组则为POST数据。参数二:是否返回进行数据表字段过滤的原始数据(布尔值)。
|
||||
|
||||
未通过验证则返回false,否则返回数组。
|
||||
|
||||
2. query($query)
|
||||
执行一条SQL语句
|
||||
|
||||
成功返回true,失败抛出DatabaseException异常。
|
||||
|
||||
3. insert($data = [])
|
||||
插入一条记录
|
||||
|
||||
传入数组为即将插入的记录
|
||||
|
||||
成功返回受影响的记录数,失败抛出DatabaseException异常。
|
||||
|
||||
4. update($data, [$param = false])
|
||||
更新一条记录
|
||||
|
||||
第一个参数为即将更新的数据,可传入第二个参数为主键。
|
||||
```
|
||||
$this->update([
|
||||
'username' => 'TOP糯米'
|
||||
], 1);
|
||||
```
|
||||
除此之外,提供另一种方式,传递更多条件或更复杂的条件
|
||||
```
|
||||
$this->update([
|
||||
'username' => 'TOP糯米'
|
||||
], function ($model) {
|
||||
$model->where('id', 1);
|
||||
});
|
||||
```
|
||||
当然,也可以使用连贯操作
|
||||
```
|
||||
$this->where('id', 1)->update([
|
||||
'username' => 'TOP糯米'
|
||||
]);
|
||||
```
|
||||
|
||||
成功返回受影响的记录数,失败抛出DatabaseException异常。
|
||||
|
||||
5. find($param = false, $notRaw = true)
|
||||
查找一条记录
|
||||
|
||||
可传入第一个参数为主键,第二个参数为是否按指定的规则(outReplace属性)进行处理。
|
||||
|
||||
一般调用
|
||||
```
|
||||
$this->find(1);
|
||||
```
|
||||
匿名函数
|
||||
```
|
||||
$this->find(function ($model) {
|
||||
$model->where('id', 1);
|
||||
});
|
||||
```
|
||||
连贯操作
|
||||
```
|
||||
$this->where('id', 1)->find();
|
||||
```
|
||||
|
||||
成功返回一个一维数组,失败抛出DatabaseException异常。
|
||||
|
||||
6. select($param = false, $notRaw = true)
|
||||
查找多条记录
|
||||
|
||||
使用方法同find
|
||||
|
||||
成功返回一个二维数组,失败抛出DatabaseException异常。
|
||||
|
||||
7. delete
|
||||
删除记录
|
||||
|
||||
直接传入主键
|
||||
```
|
||||
$this->delete(1);
|
||||
```
|
||||
匿名函数
|
||||
```
|
||||
$this->delete(function () {
|
||||
$model->where('id', 1);
|
||||
});
|
||||
```
|
||||
连贯操作
|
||||
```
|
||||
$this->where('id', 1)->delete();
|
||||
```
|
||||
|
||||
成功返回受影响的记录数,失败抛出DatabaseException异常。
|
||||
|
||||
8. count
|
||||
返回记录数
|
||||
|
||||
一般调用
|
||||
```
|
||||
$this->count();
|
||||
```
|
||||
第一个参数同样可以为匿名函数、并且同样支持连贯操作
|
||||
|
||||
成功返回记录数,失败抛出DatabaseException异常。
|
||||
|
||||
9. avg
|
||||
计算平均值
|
||||
|
||||
接收一个参数,当没有使用field方法指定字段时,可直接传入字段名,以计算平均值。
|
||||
```
|
||||
$this->avg('score');
|
||||
```
|
||||
使用field方法指定字段
|
||||
```
|
||||
$this->field('score')->avg();
|
||||
```
|
||||
匿名函数中指定字段或条件
|
||||
```
|
||||
$this->avg(function ($model) {
|
||||
$model->where('score', '>=', 60);
|
||||
$model->field('score');
|
||||
});
|
||||
```
|
||||
成功返回平均值,失败抛出DatabaseException异常。
|
||||
|
||||
10. max
|
||||
计算最大值
|
||||
|
||||
同avg方法
|
||||
|
||||
11. min
|
||||
计算最小值
|
||||
|
||||
同avg方法
|
||||
|
||||
12. sum
|
||||
求和
|
||||
|
||||
同avg方法
|
||||
|
||||
13. _sql
|
||||
返回最后执行的SQL语句
|
||||
|
||||
14. tableDesc
|
||||
返回表结构
|
||||
|
||||
接收参数为一个完整表名。
|
||||
|
||||
成功返回表结构,失败抛出DatabaseException异常。
|
||||
|
||||
15. distinct
|
||||
过滤记录中的重复值
|
||||
|
||||
接收一个为字段名称的参数
|
||||
|
||||
调用
|
||||
```
|
||||
$this->distinct('sex')->select();
|
||||
```
|
||||
|
||||
失败抛出DatabaseException异常。
|
||||
|
||||
16. effect
|
||||
删除时指定表(别)名
|
||||
|
||||
接收一个参数,可以为字符串或数组,参数为表名或表别名
|
||||
|
||||
调用
|
||||
```
|
||||
$this->delete(function ($model) {
|
||||
$model->effect('s,this');
|
||||
$model->join('left', 'score', 's')->on('s.uid = this.id');
|
||||
$model->where(['this.id' => 3]);
|
||||
});
|
||||
```
|
||||
|
||||
17. field
|
||||
指定字段
|
||||
|
||||
可传入字符串或数组
|
||||
|
||||
18. where
|
||||
指定条件
|
||||
|
||||
最多可接收三个参数
|
||||
|
||||
仅传入一个参数时,可传入字符串或数组
|
||||
```
|
||||
$where = ['id' => ['>', 10], 'sex' => 1];
|
||||
$where = 'id > 10 and sex = 1';
|
||||
$this->where($where)->select();
|
||||
```
|
||||
两个参数,解析为“字段=值”
|
||||
```
|
||||
$this->where('sex', 1)->select();
|
||||
```
|
||||
三个参数,指定字段与字段值的连接符
|
||||
```
|
||||
$this->where('sex', '>', 1)->select();
|
||||
```
|
||||
|
||||
19. order
|
||||
对结果进行排序
|
||||
|
||||
```
|
||||
$this->order('id desc')->select();
|
||||
```
|
||||
也可以使用匿名函数调用order方法
|
||||
|
||||
20. limit
|
||||
查询范围
|
||||
|
||||
接收一个参数,可以是字符串或数组
|
||||
|
||||
一般调用
|
||||
```
|
||||
$this->limit('0, 5')->select();
|
||||
$this->limit([0, 5])->select();
|
||||
```
|
||||
两种方式等效
|
||||
|
||||
21. join
|
||||
加入多表进行查询,通常情况下与on方法同时使用
|
||||
|
||||
接收三个参数,第一个参数为连接方式(空、left、right、full),第二个参数为表名(不包含前缀),第三个参数为别名(当前表会自动将”this“作为别名)。
|
||||
|
||||
一般调用
|
||||
```
|
||||
$this->select(function ($model) {
|
||||
$model->join('left', 'score', 's')->on('s.uid = this.id');
|
||||
});
|
||||
```
|
||||
同样也可以使用连贯操作
|
||||
|
||||
22. on
|
||||
表字段连接关系
|
||||
|
||||
见join方法
|
||||
|
||||
#### 属性:
|
||||
1. $table
|
||||
指定当前模型的表名(优先于模型名称)
|
||||
|
||||
```
|
||||
protected $table = 'users';
|
||||
```
|
||||
|
||||
2. $pk
|
||||
指定当前模型的主键(如果不指定,程序将自动查询以当前模型命名的表的主键)
|
||||
|
||||
```
|
||||
protected $pk = 'id';
|
||||
```
|
||||
|
||||
3. $map
|
||||
指定传入数据的键与数据库字段名称的映射关系
|
||||
|
||||
```
|
||||
protected $map = [
|
||||
'name' => 'username'
|
||||
];
|
||||
```
|
||||
|
||||
4. $inReplace
|
||||
入库时替换值
|
||||
|
||||
数据入库时自动格式化时间为unix时间戳
|
||||
```
|
||||
protected $inReplace = [
|
||||
'create_time' => ['formatTime', true]
|
||||
];
|
||||
|
||||
protected function formatTime($time)
|
||||
{
|
||||
return strtotime($time);
|
||||
}
|
||||
```
|
||||
至此,在数据在被写入数据库之前会先调用inReplace中设定的函数、方法,并将return的值作为新的值写入数据库。
|
||||
|
||||
注意:当以字段为键名的数组的值为一个字符串时,则该字符串为即将调用的函数,如果值为一个数组,且无第二个值或第二个值为false、空,则该数组第一个值为即将调用的函数,如第二个值为true,则表示当前调用的方法存在于本类或父类中。
|
||||
|
||||
5. $outReplace
|
||||
出库时替换值
|
||||
|
||||
```
|
||||
protected $outReplace = [
|
||||
'sex' => ['outFormatSex', true]
|
||||
];
|
||||
|
||||
protected function outFormatSex($sex)
|
||||
{
|
||||
switch ($sex) {
|
||||
case 1:
|
||||
return '男';
|
||||
break;
|
||||
case 2:
|
||||
return '女';
|
||||
break;
|
||||
default:
|
||||
return '未知';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
注意:当以字段为键名的数组的值为一个字符串时,则该字符串为即将调用的函数,如果值为一个数组,且无第二个值或第二个值为false、空,则该数组第一个值为即将调用的函数,如第二个值为true,则表示当前调用的方法存在于本类或父类中。
|
||||
|
||||
6. $updateReplace
|
||||
数据更新时替换值
|
||||
|
||||
基本类似于inReplace,但仅当执行更新操作时执行。
|
||||
|
||||
7. $validate
|
||||
自动验证
|
||||
|
||||
验证不为空
|
||||
```
|
||||
protected $validate = [
|
||||
'username' => ['notNull', '用户名不能为空'],
|
||||
];
|
||||
```
|
||||
验证不等于
|
||||
```
|
||||
protected $validate = [
|
||||
'username' => ['notEqual', '0', '用户名不能为0'],
|
||||
];
|
||||
```
|
||||
多条件(用户名不为空且不为0)
|
||||
```
|
||||
protected $validate = [
|
||||
'username' => [
|
||||
['notNull', '用户名不能为空'],
|
||||
['notEqual', '0', '用户名不能为0'],
|
||||
],
|
||||
];
|
||||
```
|
||||
自定义函数验证,新建函数demo到函数库
|
||||
```
|
||||
function demo($name, $n1, $n2)
|
||||
{
|
||||
if ($name == $n1 || $name == $n2) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
添加到自动验证
|
||||
```
|
||||
protected $validate = [
|
||||
'username' => [
|
||||
['notNull', '用户名不能为空'],
|
||||
['notEqual', '0', '用户名不能为0'],
|
||||
['demo', 'TOP糯米', '张三', '用户名不能为TOP糯米或张三'],
|
||||
],
|
||||
];
|
||||
```
|
||||
|
||||
### 调用模型
|
||||
调用模型有两种方式:
|
||||
1. model函数(推荐)
|
||||
model函数会返回一个模型的单例,使用方式与直接new无差别。
|
||||
```
|
||||
$object = model(模型);
|
||||
```
|
||||
2. new 模型
|
||||
```
|
||||
$object = new 模型();
|
||||
```
|
||||
|
||||
## 模板
|
||||
### 模板继承
|
||||
模板继承通过extend标签与block标签配合使用实现。
|
||||
一个最简单的继承
|
||||
```
|
||||
// Base/layout.html(父级模板)
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
<block name="body"></block>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
// Index/index.html
|
||||
|
||||
<extend file="Base/layout" />
|
||||
<block name="body">
|
||||
<h3>内容主体</h3>
|
||||
</block>
|
||||
```
|
||||
### 模板标签
|
||||
内置一些常用标签
|
||||
1. php
|
||||
|
||||
php标签。此标签为闭合标签,标签内的内容将被解析为原生php代码执行。
|
||||
|
||||
```
|
||||
<php>
|
||||
echo '你好';
|
||||
</php>
|
||||
```
|
||||
|
||||
2. if
|
||||
|
||||
if标签。此标签为闭合标签,condition属性为if的条件,属性列表:condition。
|
||||
|
||||
```
|
||||
<if condition="$age eq 10">
|
||||
// do something...
|
||||
</if>
|
||||
```
|
||||
|
||||
3. else
|
||||
|
||||
else标签。此标签为自闭合标签,可选属性condition,存在condition属性则被解析为elseif,属性列表:condition(可选)。
|
||||
|
||||
```
|
||||
<if condition="$age eq 10">
|
||||
// do something...
|
||||
<else />
|
||||
// do something...
|
||||
</if>
|
||||
|
||||
<if condition="$age eq 10">
|
||||
// do something...
|
||||
<else condition="$age eq 20" />
|
||||
// do something...
|
||||
</if>
|
||||
```
|
||||
|
||||
4. volist
|
||||
|
||||
循环标签。此标签为闭合标签,属性列表:name、id、key(可选)。
|
||||
|
||||
```
|
||||
<volist name="lists" id="item">
|
||||
{$item['id']}
|
||||
</volist>
|
||||
|
||||
<volist name="lists" id="item" key="i">
|
||||
{$i}、{$item['id']}
|
||||
</volist>
|
||||
```
|
||||
|
||||
5. assign
|
||||
|
||||
赋值标签,在模板中创建新的php变量。此标签为自闭合标签,属性列表:name、value。
|
||||
|
||||
```
|
||||
<assign name="username" value="TOP糯米" />
|
||||
```
|
||||
|
||||
6. raw
|
||||
|
||||
该标签为闭合标签。raw标签中的内容不会被编译。
|
||||
|
||||
```
|
||||
<raw>
|
||||
<volist name="lists" id="item">
|
||||
{$item['id']}
|
||||
</volist>
|
||||
</raw>
|
||||
```
|
||||
上例,volist标签会被原样输出。
|
||||
|
||||
7. 变量、函数输出
|
||||
```
|
||||
// 变量输出
|
||||
{$username}
|
||||
|
||||
// 调用函数,左定界符后加上:表示调用函数
|
||||
{:mb_substr($username, 0, 3, 'utf8')}
|
||||
```
|
||||
|
||||
### 自定义标签
|
||||
新建自定义标签库类文件/application/home/taglib/Extend.php,目录及文件名称没有要求。
|
||||
#### 闭合标签
|
||||
```
|
||||
namespace app\home\taglib;
|
||||
|
||||
class Extend
|
||||
{
|
||||
public $tags = [
|
||||
'test' => ['attr' => 'start,length,id', 'close' => 1]
|
||||
];
|
||||
|
||||
public function _test($tag, $content)
|
||||
{
|
||||
$parse = '<?php ';
|
||||
$parse .= 'for ($' . $tag['id'] . ' = ' . $tag['start'] . '; $' . $tag['id'];
|
||||
$parse .= ' < ' . $tag['start'] . ' + ' . $tag['length'] . '; ';
|
||||
$parse .= '$' . $tag['id'] . '++): ?>';
|
||||
$parse .= $content;
|
||||
$parse .= '<?php endfor; ?>';
|
||||
return $parse;
|
||||
}
|
||||
}
|
||||
```
|
||||
类创建完成后,到配置文件config.php的view下的tagLib中添加Extend类
|
||||
```
|
||||
'view' => [
|
||||
'tagLib' => [
|
||||
\app\home\taglib\Extend::class
|
||||
]
|
||||
],
|
||||
```
|
||||
添加完成后即可在模板中使用
|
||||
```
|
||||
<test start="1" length="10" id="test">
|
||||
{$test}
|
||||
</test>
|
||||
```
|
||||
#### 自闭合标签
|
||||
添加一个描述
|
||||
```
|
||||
'say' => ['attr' => 'what', 'close' => 0]
|
||||
```
|
||||
新建_say方法
|
||||
```
|
||||
public function _say($tag)
|
||||
{
|
||||
return "<?php echo '{$tag['what']}'; ?>";
|
||||
}
|
||||
```
|
||||
模板调用
|
||||
```
|
||||
<say what="Hello world!" />
|
||||
```
|
||||
|
||||
## 自定义路由
|
||||
路由配置文件位于 application 下,文件名:route.php
|
||||
现有News控制器中的detail方法
|
||||
```
|
||||
public function detail($id)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $id
|
||||
];
|
||||
}
|
||||
```
|
||||
假设访问地址为: http://127.0.0.3/home/news/detail/id/1.html 。
|
||||
### 必须参数
|
||||
添加如下规则
|
||||
```
|
||||
'detail' => [
|
||||
'[id]',
|
||||
'home/news/detail'
|
||||
]
|
||||
```
|
||||
完成后,可使用 http://127.0.0.3/detail/1.html 访问到对应位置。
|
||||
### 可选参数
|
||||
修改detail方法
|
||||
```
|
||||
public function detail($id = 0)
|
||||
{
|
||||
return [
|
||||
'id' => (int) $id
|
||||
];
|
||||
}
|
||||
```
|
||||
添加路由规则
|
||||
```
|
||||
'detail' => [
|
||||
'[:id]',
|
||||
'home/news/detail'
|
||||
]
|
||||
```
|
||||
完成后,可使用 http://127.0.0.3/detail.html 访问到对应位置,如果没传递id,则使用默认值。
|
||||
### 多个参数
|
||||
```
|
||||
'detail' => [
|
||||
'[id][:type]',
|
||||
'home/news/detail'
|
||||
]
|
||||
```
|
||||
|
||||
## 其他
|
||||
### Request类
|
||||
获取实例
|
||||
1. instance方法获取单例
|
||||
```
|
||||
Request::instance();
|
||||
```
|
||||
2. request函数获取单例
|
||||
```
|
||||
request();
|
||||
```
|
||||
|
||||
#### 供调用的方法
|
||||
1. isPost
|
||||
|
||||
判断是否是POST请求
|
||||
|
||||
2. isGet
|
||||
|
||||
判断是否是GET请求
|
||||
|
||||
3. isPut
|
||||
|
||||
判断是否是PUT请求
|
||||
|
||||
4. isDelete
|
||||
|
||||
判断是否是DELETE请求
|
||||
|
||||
5. isHead
|
||||
|
||||
判断是否是HEAD请求
|
||||
|
||||
6. isPatch
|
||||
|
||||
判断是否是PATCH请求
|
||||
|
||||
7. isOptions
|
||||
|
||||
判断是否是OPTIONS请求
|
||||
|
||||
8. isAjax
|
||||
|
||||
判断是否是AJAX请求
|
||||
|
||||
9. create
|
||||
|
||||
创建一个HTTP请求
|
||||
|
||||
原型:create($url, $data = [], $header = [])
|
||||
|
||||
第一个参数为请求的链接,第二个参数为将要POST的数据,第三个参数为指定Header参数
|
||||
|
||||
10. ip
|
||||
|
||||
返回客户端IP地址
|
||||
|
||||
11. module
|
||||
|
||||
当前请求的模型名称
|
||||
|
||||
12. classname
|
||||
|
||||
当前请求的完整控制器名称
|
||||
|
||||
13. controller
|
||||
|
||||
当前请求的不包含命名空间的控制器名称
|
||||
|
||||
14. method
|
||||
|
||||
当前请求的方法名称
|
||||
|
||||
15. params
|
||||
|
||||
当前请求所带的参数
|
||||
|
||||
16. get
|
||||
|
||||
获取get数据
|
||||
|
||||
原型:get($name = '*', $except = [], $filter = 'filter')
|
||||
|
||||
第一个参数为将要获取的变量名称(' * ' 为全部),第二个参数为过滤的变量,第三个参数为指定的过滤函数(可以为自定义函数名称或匿名函数)。
|
||||
|
||||
函数名称:
|
||||
```
|
||||
request()->get('id', ['type'], 'filter');
|
||||
```
|
||||
匿名函数:
|
||||
```
|
||||
request()->get('id', ['type'], function ($value) {
|
||||
return (int) $value;
|
||||
});
|
||||
```
|
||||
|
||||
17. post
|
||||
|
||||
获取post数据
|
||||
|
||||
使用同get方法
|
||||
|
||||
18. except
|
||||
|
||||
指定过滤的变量
|
||||
|
||||
取出全部get数据,但不包括type
|
||||
```
|
||||
request()->except('type')->get();
|
||||
```
|
||||
|
||||
### 面向控制器的前置、后置方法(请求拦截)
|
||||
创建application/home/filter/Auth.php测试文件
|
||||
```
|
||||
namespace app\home\filter;
|
||||
|
||||
use top\middleware\ifs\MiddlewareIfs;
|
||||
|
||||
class Auth implements MiddlewareIfs
|
||||
{
|
||||
public function before()
|
||||
{
|
||||
return '拒绝请求';
|
||||
}
|
||||
|
||||
public function after($data)
|
||||
{
|
||||
// TODO: Implement after() method.
|
||||
}
|
||||
}
|
||||
```
|
||||
创建完成后,加入配置
|
||||
```
|
||||
'middleware' => [
|
||||
\app\home\filter\Auth::class
|
||||
],
|
||||
```
|
||||
现在,访问项目则会得到 ' 拒绝请求 ' 结果。仅当before方法return的值为true时,程序才会继续执行,否则return等效于控制器方法的return。
|
|
@ -1,9 +0,0 @@
|
|||
<?php
|
||||
return [
|
||||
'db' => [
|
||||
'port' => 3306
|
||||
],
|
||||
'middleware' => [
|
||||
\app\home\middleware\Test::class
|
||||
],
|
||||
];
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use top\library\Controller;
|
||||
|
||||
class Common extends Controller
|
||||
{
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\controller;
|
||||
|
||||
use top\library\cache\Redis;
|
||||
|
||||
class Index
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function hello()
|
||||
{
|
||||
return 'hello';
|
||||
}
|
||||
|
||||
public function testPage()
|
||||
{
|
||||
// return $this->view();
|
||||
return [];
|
||||
}
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
<?php
|
|
@ -1,19 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\middleware;
|
||||
|
||||
use top\middleware\ifs\MiddlewareIfs;
|
||||
|
||||
class Test implements MiddlewareIfs
|
||||
{
|
||||
|
||||
public function before()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function after($data)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\model;
|
||||
|
||||
use top\library\Model;
|
||||
|
||||
/**
|
||||
* 模型示例
|
||||
* @package app\home\model
|
||||
*/
|
||||
class Example extends Model
|
||||
{
|
||||
|
||||
protected $table = 'example';
|
||||
protected $pk = 'id';
|
||||
protected $map = [
|
||||
'type' => 'user_type'
|
||||
];
|
||||
|
||||
protected $insertHandle = [
|
||||
'' => 'time',
|
||||
'' => ['getIntTime', true]
|
||||
];
|
||||
|
||||
protected $updateHandle = [
|
||||
'' => ['getIntTime', true]
|
||||
];
|
||||
|
||||
// 出库
|
||||
protected $outHandle = [
|
||||
'' => [
|
||||
1 => '一',
|
||||
]
|
||||
];
|
||||
|
||||
// 数据验证
|
||||
protected $validate = [
|
||||
'' => [
|
||||
['notEqual', 0, 'tips'],
|
||||
['notNull', 'tips']
|
||||
],
|
||||
'' => ['notNull', 'tips']
|
||||
];
|
||||
|
||||
/**
|
||||
* 将字符串时间格式化为unix时间戳
|
||||
* @param $param
|
||||
* @return false|int
|
||||
*/
|
||||
public function getIntTime($param)
|
||||
{
|
||||
return strtotime($param);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\model;
|
||||
|
||||
use top\library\Model;
|
||||
|
||||
class Users extends Model
|
||||
{
|
||||
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace app\home\taglib;
|
||||
|
||||
class Extend
|
||||
{
|
||||
public $tags = [
|
||||
'say' => ['attr' => 'what', 'close' => 0],
|
||||
'lists' => ['attr' => 'name', 'close' => 1]
|
||||
];
|
||||
|
||||
public function _say($tag)
|
||||
{
|
||||
return '<?php echo \'' . $tag['what'] . '\'; ?>';
|
||||
}
|
||||
|
||||
public function _lists($tag, $content)
|
||||
{
|
||||
$parse = "<?php echo '{$tag['name']} start'; ?>";
|
||||
$parse .= $content;
|
||||
$parse .= "<?php echo '{$tag['name']} end'; ?>";
|
||||
return $parse;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
a.html
|
||||
<include file="Base/b" />
|
|
@ -1 +0,0 @@
|
|||
b.html
|
|
@ -1,11 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
父级模板
|
||||
<block name="body"></block>
|
||||
</body>
|
||||
</html>
|
|
@ -1,27 +0,0 @@
|
|||
<extend file="Base/common" />
|
||||
|
||||
<block name="body">
|
||||
BODY
|
||||
<raw>
|
||||
<volist name="b" id="vo">
|
||||
<if condition="$a == 1">
|
||||
{$a}
|
||||
<else condition="$a == 2" />
|
||||
{$b}
|
||||
</if>
|
||||
</volist>
|
||||
</raw>
|
||||
{:date('Y-m-d H:i:s', time())}
|
||||
<include file="Base/a" />
|
||||
<say what="你好" />
|
||||
cut
|
||||
<lists name="one">
|
||||
content
|
||||
<lists name="two">
|
||||
content
|
||||
<lists name="three">
|
||||
content
|
||||
</lists>
|
||||
</lists>
|
||||
</lists>
|
||||
</block>
|
|
@ -1,17 +0,0 @@
|
|||
<?php
|
||||
// 自定义路由示例
|
||||
|
||||
return [
|
||||
'login' => [
|
||||
null,
|
||||
'home/example/login'
|
||||
],
|
||||
'example-detail' => [
|
||||
'[id]',
|
||||
'home/example/detail'
|
||||
],
|
||||
'example' => [
|
||||
'[:type]',
|
||||
'home/example/index'
|
||||
],
|
||||
];
|
|
@ -26,9 +26,7 @@ return [
|
|||
],
|
||||
'view' => [
|
||||
'engine' => 'Top',
|
||||
'tagLib' => [
|
||||
\app\home\taglib\Extend::class
|
||||
],
|
||||
'tagLib' => [],
|
||||
'ext' => 'html',
|
||||
'dir' => '',
|
||||
'cacheDir' => '',
|
||||
|
|
|
@ -123,7 +123,7 @@ class Create
|
|||
{
|
||||
$file = $this->projectPath . '../route.php';
|
||||
if (!file_exists($file)) {
|
||||
if (!file_put_contents($file, file_get_contents($this->dir . 'route.tpl'))) {
|
||||
if (!file_put_contents($file, file_get_contents($this->dir . 'tpl/route.tpl'))) {
|
||||
exit('-8');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,6 @@ class Demo extends Model
|
|||
|
||||
public function get()
|
||||
{
|
||||
return 'Hello';
|
||||
return '模块{name}正在运行...';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
{$hello}
|
||||
<h3>{$hello}</h3>
|
||||
<hr>
|
||||
<p style="color: #666666; text-align: center; font-size: 13px;">TOP-Framework</p>
|
||||
</body>
|
||||
</html>
|
|
@ -231,7 +231,7 @@ class Database
|
|||
/**
|
||||
* 查询一条记录
|
||||
* @param bool $param
|
||||
* @return object
|
||||
* @return mixed
|
||||
*/
|
||||
public function find($param = false)
|
||||
{
|
||||
|
@ -246,7 +246,7 @@ class Database
|
|||
$this->where([$field => $param]);
|
||||
$result = self::$driver->find($this->table, $this->distinct, $this->field, $this->join, $this->on, $this->where, $this->order);
|
||||
$this->_reset();
|
||||
return (object)$result;
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -269,7 +269,7 @@ class Database
|
|||
$result = self::$driver->select($this->table, $this->distinct, $this->field, $this->join, $this->on, $this->where, $this->order, $this->limit);
|
||||
$this->_reset();
|
||||
foreach ($result as $k => $v)
|
||||
$result[$k] = (object)$v;
|
||||
$result[$k] = $v;
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -22,13 +22,13 @@ class Model
|
|||
protected $map = [];
|
||||
|
||||
// insert值映射
|
||||
protected $insertHandle = [];
|
||||
protected $inReplace = [];
|
||||
|
||||
// update值映射
|
||||
protected $updateHandle = [];
|
||||
protected $updateReplace = [];
|
||||
|
||||
// 出库值映射
|
||||
protected $outHandle = [];
|
||||
protected $outReplace = [];
|
||||
|
||||
// 模型消息(请注意:在方法中赋值会覆盖掉数据验证的message)
|
||||
protected $message = '';
|
||||
|
@ -327,7 +327,8 @@ class Model
|
|||
return $mapData;
|
||||
} else {
|
||||
$data = [];
|
||||
$tableDesc = $this->tableDesc();
|
||||
$prefix = Config::instance()->get('db')['prefix'];
|
||||
$tableDesc = $this->tableDesc($prefix . $this->table);
|
||||
foreach ($tableDesc as $value) {
|
||||
if (array_key_exists($value['Field'], $mapData)) {
|
||||
// 如果表单值为空则赋值为数据库字段默认值
|
||||
|
@ -399,7 +400,7 @@ class Model
|
|||
*/
|
||||
private function inHandle($data)
|
||||
{
|
||||
$replace = ($this->isInsert) ? $this->insertHandle : $this->updateHandle;
|
||||
$replace = ($this->isInsert) ? $this->inReplace : $this->updateReplace;
|
||||
foreach ($replace as $key => $value) {
|
||||
$fieldValue = '';
|
||||
if (!array_key_exists($key, $data)) {
|
||||
|
@ -440,19 +441,15 @@ class Model
|
|||
*/
|
||||
private function outHandle($data)
|
||||
{
|
||||
foreach ($this->outHandle as $key => $value) {
|
||||
foreach ($this->outReplace as $key => $value) {
|
||||
if (count($data) == count($data, 1)) {
|
||||
if (array_key_exists($key, $data)) {
|
||||
if (array_key_exists($data[$key], $value)) {
|
||||
$data[$key] = $value[$data[$key]];
|
||||
}
|
||||
$data[$key] = $this->callOutReplaceFunction($data[$key], $value);
|
||||
}
|
||||
} else {
|
||||
foreach ($data as $k => $v) {
|
||||
if (array_key_exists($key, $v)) {
|
||||
if (array_key_exists($v[$key], $value)) {
|
||||
$data[$k][$key] = $value[$v[$key]];
|
||||
}
|
||||
$data[$k][$key] = $this->callOutReplaceFunction($data[$k][$key], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -460,6 +457,27 @@ class Model
|
|||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用函数、方法替换值
|
||||
* @param $value
|
||||
* @param $function
|
||||
* @return mixed
|
||||
*/
|
||||
private function callOutReplaceFunction($value, $function)
|
||||
{
|
||||
if (is_array($function) && (isset($function[1]) && $function[1] === true)) {
|
||||
$value = $this->{$function[0]}($value);
|
||||
} else {
|
||||
if (is_array($function)) {
|
||||
$function = $function[0];
|
||||
}
|
||||
if (function_exists($function)) {
|
||||
$value = $function($value);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证表单
|
||||
* @param $data
|
||||
|
|
|
@ -3,17 +3,16 @@
|
|||
/**
|
||||
* 过滤数组
|
||||
* @param array $array
|
||||
* @param array $except
|
||||
* @param string $filter
|
||||
* @param array $result
|
||||
*/
|
||||
function filterArray($array = [], $except = [], $filter = 'filter', &$result = [])
|
||||
function filterArray($array = [], $filter = 'filter', &$result = [])
|
||||
{
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$this->processArray($value, $result[$key]);
|
||||
filterArray($value, $result[$key]);
|
||||
} else {
|
||||
$result[$key] = (in_array($key, $except) || !$filter) ? $value : $filter($value);
|
||||
$result[$key] = (!$filter) ? $value : $filter($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -230,7 +230,7 @@ class Request
|
|||
public function except($field = null)
|
||||
{
|
||||
if (is_array($field)) {
|
||||
$this->except = array_merge($field, $this->except);
|
||||
$this->except = array_merge($this->except, $field);
|
||||
} elseif ($field) {
|
||||
$this->except[] = $field;
|
||||
}
|
||||
|
@ -244,7 +244,7 @@ class Request
|
|||
* @param string $filter
|
||||
* @return null
|
||||
*/
|
||||
public function get($name = null, $except = [], $filter = 'filter')
|
||||
public function get($name = '*', $except = [], $filter = 'filter')
|
||||
{
|
||||
return $this->requestData('get', $name, $except, $filter);
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ class Request
|
|||
* @param string $filter
|
||||
* @return null
|
||||
*/
|
||||
public function post($name = null, $except = [], $filter = 'filter')
|
||||
public function post($name = '*', $except = [], $filter = 'filter')
|
||||
{
|
||||
return $this->requestData('post', $name, $except, $filter);
|
||||
}
|
||||
|
@ -274,12 +274,11 @@ class Request
|
|||
$data = ($type == 'get') ? $_GET : $_POST;
|
||||
$name = ($name == '*') ? null : $name;
|
||||
|
||||
// 过滤数组
|
||||
if (!is_array($except)) {
|
||||
$except = [$except];
|
||||
$except = explode(',', $except);
|
||||
}
|
||||
filterArray($data, $except, $filter, $data);
|
||||
|
||||
$this->except = array_merge($this->except, $except);
|
||||
// 移除指定的值
|
||||
foreach ($this->except as $key => $value) {
|
||||
if (isset($data[$value])) {
|
||||
|
@ -290,6 +289,8 @@ class Request
|
|||
// 重置except的值
|
||||
$this->except = [];
|
||||
|
||||
filterArray($data, $filter, $data);
|
||||
|
||||
if ($name) {
|
||||
if (isset($data[$name])) {
|
||||
return $data[$name];
|
||||
|
@ -415,7 +416,7 @@ class Request
|
|||
$beforeReturnData = $object->{$beforeMethod}();
|
||||
}
|
||||
|
||||
if ($beforeReturnData === null || $beforeReturnData === '') {
|
||||
if ($beforeReturnData === null || $beforeReturnData === '' || $beforeReturnData === true) {
|
||||
$reflectionMethod = new \ReflectionMethod($ctrl, $method);
|
||||
$data = $reflectionMethod->invokeArgs($object, $params);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ class Pathinfo implements RouteIfs
|
|||
$params = [];
|
||||
for ($i = 0; $i < count($this->uriArray); $i = $i + 2) {
|
||||
if (isset($this->uriArray[$i + 1]) && $this->uriArray[$i + 1] != '') {
|
||||
// $_GET[$this->uriArray[$i]] = $this->uriArray[$i + 1];
|
||||
$_GET[$this->uriArray[$i]] = $this->uriArray[$i + 1];
|
||||
if (isset($paramNameArray[$this->uriArray[$i]])) {
|
||||
$params[$this->uriArray[$i]] = $this->uriArray[$i + 1];
|
||||
}
|
||||
|
|
|
@ -278,6 +278,10 @@ class Engine
|
|||
$attr = $item['attr'] ? $this->getAttr($node['start_str'], explode(',', $item['attr'])) : [];
|
||||
// 得到准备替换的值
|
||||
$replace = explode($cut, $this->getTagParseResult($method, $attr, $cut));
|
||||
$replace = [
|
||||
(isset($replace[0])) ? $replace[0] : [],
|
||||
(isset($replace[1])) ? $replace[1] : [],
|
||||
];
|
||||
while ($startArray) {
|
||||
$begin = end($startArray);
|
||||
// 如果当前结束位置大于最后一个开始标签的位置,则跳过,直接去替换这个结束标签
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1,2 +0,0 @@
|
|||
/*! layer mobile-v2.0.0 Web弹层组件 MIT License http://layer.layui.com/mobile By 贤心 */
|
||||
;!function(e){"use strict";var t=document,n="querySelectorAll",i="getElementsByClassName",a=function(e){return t[n](e)},s={type:0,shade:!0,shadeClose:!0,fixed:!0,anim:"scale"},l={extend:function(e){var t=JSON.parse(JSON.stringify(s));for(var n in e)t[n]=e[n];return t},timer:{},end:{}};l.touch=function(e,t){e.addEventListener("click",function(e){t.call(this,e)},!1)};var r=0,o=["layui-m-layer"],c=function(e){var t=this;t.config=l.extend(e),t.view()};c.prototype.view=function(){var e=this,n=e.config,s=t.createElement("div");e.id=s.id=o[0]+r,s.setAttribute("class",o[0]+" "+o[0]+(n.type||0)),s.setAttribute("index",r);var l=function(){var e="object"==typeof n.title;return n.title?'<h3 style="'+(e?n.title[1]:"")+'">'+(e?n.title[0]:n.title)+"</h3>":""}(),c=function(){"string"==typeof n.btn&&(n.btn=[n.btn]);var e,t=(n.btn||[]).length;return 0!==t&&n.btn?(e='<span yes type="1">'+n.btn[0]+"</span>",2===t&&(e='<span no type="0">'+n.btn[1]+"</span>"+e),'<div class="layui-m-layerbtn">'+e+"</div>"):""}();if(n.fixed||(n.top=n.hasOwnProperty("top")?n.top:100,n.style=n.style||"",n.style+=" top:"+(t.body.scrollTop+n.top)+"px"),2===n.type&&(n.content='<i></i><i class="layui-m-layerload"></i><i></i><p>'+(n.content||"")+"</p>"),n.skin&&(n.anim="up"),"msg"===n.skin&&(n.shade=!1),s.innerHTML=(n.shade?"<div "+("string"==typeof n.shade?'style="'+n.shade+'"':"")+' class="layui-m-layershade"></div>':"")+'<div class="layui-m-layermain" '+(n.fixed?"":'style="position:static;"')+'><div class="layui-m-layersection"><div class="layui-m-layerchild '+(n.skin?"layui-m-layer-"+n.skin+" ":"")+(n.className?n.className:"")+" "+(n.anim?"layui-m-anim-"+n.anim:"")+'" '+(n.style?'style="'+n.style+'"':"")+">"+l+'<div class="layui-m-layercont">'+n.content+"</div>"+c+"</div></div></div>",!n.type||2===n.type){var d=t[i](o[0]+n.type),y=d.length;y>=1&&layer.close(d[0].getAttribute("index"))}document.body.appendChild(s);var u=e.elem=a("#"+e.id)[0];n.success&&n.success(u),e.index=r++,e.action(n,u)},c.prototype.action=function(e,t){var n=this;e.time&&(l.timer[n.index]=setTimeout(function(){layer.close(n.index)},1e3*e.time));var a=function(){var t=this.getAttribute("type");0==t?(e.no&&e.no(),layer.close(n.index)):e.yes?e.yes(n.index):layer.close(n.index)};if(e.btn)for(var s=t[i]("layui-m-layerbtn")[0].children,r=s.length,o=0;o<r;o++)l.touch(s[o],a);if(e.shade&&e.shadeClose){var c=t[i]("layui-m-layershade")[0];l.touch(c,function(){layer.close(n.index,e.end)})}e.end&&(l.end[n.index]=e.end)},e.layer={v:"2.0",index:r,open:function(e){var t=new c(e||{});return t.index},close:function(e){var n=a("#"+o[0]+e)[0];n&&(n.innerHTML="",t.body.removeChild(n),clearTimeout(l.timer[e]),delete l.timer[e],"function"==typeof l.end[e]&&l.end[e](),delete l.end[e])},closeAll:function(){for(var e=t[i](o[0]),n=0,a=e.length;n<a;n++)layer.close(0|e[0].getAttribute("index"))}},"function"==typeof define?define(function(){return layer}):function(){var e=document.scripts,n=e[e.length-1],i=n.src,a=i.substring(0,i.lastIndexOf("/")+1);n.getAttribute("merge")||document.head.appendChild(function(){var e=t.createElement("link");return e.href=a+"need/layer.css?2.0",e.type="text/css",e.rel="styleSheet",e.id="layermcss",e}())}()}(window);
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 5.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 5.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 701 B |
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
|
@ -1,2 +0,0 @@
|
|||
/*! layer mobile-v2.0 弹层组件移动版 License LGPL http://layer.layui.com/mobile By 贤心 */
|
||||
;!function(a){"use strict";var b=document,c="querySelectorAll",d="getElementsByClassName",e=function(a){return b[c](a)},f={type:0,shade:!0,shadeClose:!0,fixed:!0,anim:"scale"},g={extend:function(a){var b=JSON.parse(JSON.stringify(f));for(var c in a)b[c]=a[c];return b},timer:{},end:{}};g.touch=function(a,b){a.addEventListener("click",function(a){b.call(this,a)},!1)};var h=0,i=["layui-m-layer"],j=function(a){var b=this;b.config=g.extend(a),b.view()};j.prototype.view=function(){var a=this,c=a.config,f=b.createElement("div");a.id=f.id=i[0]+h,f.setAttribute("class",i[0]+" "+i[0]+(c.type||0)),f.setAttribute("index",h);var g=function(){var a="object"==typeof c.title;return c.title?'<h3 style="'+(a?c.title[1]:"")+'">'+(a?c.title[0]:c.title)+"</h3>":""}(),j=function(){"string"==typeof c.btn&&(c.btn=[c.btn]);var a,b=(c.btn||[]).length;return 0!==b&&c.btn?(a='<span yes type="1">'+c.btn[0]+"</span>",2===b&&(a='<span no type="0">'+c.btn[1]+"</span>"+a),'<div class="layui-m-layerbtn">'+a+"</div>"):""}();if(c.fixed||(c.top=c.hasOwnProperty("top")?c.top:100,c.style=c.style||"",c.style+=" top:"+(b.body.scrollTop+c.top)+"px"),2===c.type&&(c.content='<i></i><i class="layui-m-layerload"></i><i></i><p>'+(c.content||"")+"</p>"),c.skin&&(c.anim="up"),"msg"===c.skin&&(c.shade=!1),f.innerHTML=(c.shade?"<div "+("string"==typeof c.shade?'style="'+c.shade+'"':"")+' class="layui-m-layershade"></div>':"")+'<div class="layui-m-layermain" '+(c.fixed?"":'style="position:static;"')+'><div class="layui-m-layersection"><div class="layui-m-layerchild '+(c.skin?"layui-m-layer-"+c.skin+" ":"")+(c.className?c.className:"")+" "+(c.anim?"layui-m-anim-"+c.anim:"")+'" '+(c.style?'style="'+c.style+'"':"")+">"+g+'<div class="layui-m-layercont">'+c.content+"</div>"+j+"</div></div></div>",!c.type||2===c.type){var k=b[d](i[0]+c.type),l=k.length;l>=1&&layer.close(k[0].getAttribute("index"))}document.body.appendChild(f);var m=a.elem=e("#"+a.id)[0];c.success&&c.success(m),a.index=h++,a.action(c,m)},j.prototype.action=function(a,b){var c=this;a.time&&(g.timer[c.index]=setTimeout(function(){layer.close(c.index)},1e3*a.time));var e=function(){var b=this.getAttribute("type");0==b?(a.no&&a.no(),layer.close(c.index)):a.yes?a.yes(c.index):layer.close(c.index)};if(a.btn)for(var f=b[d]("layui-m-layerbtn")[0].children,h=f.length,i=0;h>i;i++)g.touch(f[i],e);if(a.shade&&a.shadeClose){var j=b[d]("layui-m-layershade")[0];g.touch(j,function(){layer.close(c.index,a.end)})}a.end&&(g.end[c.index]=a.end)},a.layer={v:"2.0",index:h,open:function(a){var b=new j(a||{});return b.index},close:function(a){var c=e("#"+i[0]+a)[0];c&&(c.innerHTML="",b.body.removeChild(c),clearTimeout(g.timer[a]),delete g.timer[a],"function"==typeof g.end[a]&&g.end[a](),delete g.end[a])},closeAll:function(){for(var a=b[d](i[0]),c=0,e=a.length;e>c;c++)layer.close(0|a[0].getAttribute("index"))}},"function"==typeof define?define(function(){return layer}):function(){var a=document.scripts,c=a[a.length-1],d=c.src,e=d.substring(0,d.lastIndexOf("/")+1);c.getAttribute("merge")||document.head.appendChild(function(){var a=b.createElement("link");return a.href=e+"need/layer.css?2.0",a.type="text/css",a.rel="styleSheet",a.id="layermcss",a}())}()}(window);
|
File diff suppressed because one or more lines are too long
|
@ -1,34 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
</head>
|
||||
<body>
|
||||
父级模板
|
||||
|
||||
BODY
|
||||
|
||||
<volist name="b" id="vo">
|
||||
<if condition="$a == 1">
|
||||
{$a}
|
||||
<else condition="$a == 2" />
|
||||
{$b}
|
||||
</if>
|
||||
</volist>
|
||||
|
||||
<?php echo (date('Y-m-d H:i:s', time())); ?>
|
||||
a.html
|
||||
b.html
|
||||
<?php echo '你好'; ?>
|
||||
cut
|
||||
<?php echo 'one start'; ?>
|
||||
content
|
||||
<?php echo 'two start'; ?>
|
||||
content
|
||||
<?php echo 'three start'; ?>
|
||||
content
|
||||
<?php echo 'three end'; echo 'two end'; echo 'one end'; ?>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue