代码拉取完成,页面将自动刷新
//$app_path 项目路径
//$default_app 默认应用
__construct($app_path, $default_app = null)
#!/usr/bin/env php
<?php
require __DIR__ . '/vendor/autoload.php';
(new \zqphp\Load(__DIR__ . '/app'))->start();
├── app 应用目录
├── config 配置目录
│ ├── app.php 应用配置
│ ├── database.php 数据库配置
│ ├── session.php Session配置
│ ├── view.php 视图配置
│ └── worker.php workerman配置
│ └── swoole.php swoole配置
├── public 静态资源目录
└── zqphp 启动文件
<?php
require __DIR__ . '/../vendor/autoload.php';
(new \zqphp\Load(__DIR__ . '/../app'))->run();
*Apache伪静态(.htaccess)
<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,PT,L]
</IfModule>
*Nginx伪静态
if (!-d $request_filename){
set $rule_0 1$rule_0;
}
if (!-f $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite ^/(.*)$ /index.php last;
}
*iis伪静态(web.config)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="index" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true"/>
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true"/>
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true"/>
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
<?php
return [
//默认PHP类名
'app_sort' => 'index',
//默认方法名
'app_method' => 'main',
//默认方法开关(多级)
'method_switch' => false,
//项目内的PHP文件夹,Lib第一层文件不用命名空间,第二层起要加命名空间
'php_dir' => 'controller',
// 默认应用
'default_app' => 'admin',
// 应用映射
'app_map' => ['back' => 'admin', 'home'],
//路由参数分隔符
'route_parameter' => '_',
//访问默认支持格式
'route_format' => ['php', 'html'],
//对外开放类名加前缀 (可为空)
'sort_prefix' => '',
//推荐对外开放方法名加前缀 (可为空)
'method_prefix' => '',
// 默认时区
'default_timezone' => 'Asia/Shanghai',
// 错误显示信息,非调试模式有效
'error_message' => '404 Not Found',
// 显示错误信息
'show_error_msg' => true,
];
<?php
//https://www.kancloud.cn/manual/think-orm/1257999
return [
// 默认使用的数据库连接配置
'default' => 'mysql',
// 自定义时间查询规则
'time_query_rule' => [],
// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp' => true,
// 时间字段取出后的默认时间格式
'datetime_format' => 'Y-m-d H:i:s',
// 时间字段配置 配置格式:create_time,update_time
'datetime_field' => '',
// 数据库连接配置信息
'connections' => [
'mysql' => [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '127.0.0.1',
// 数据库名
'database' => 'database',
// 用户名
'username' => 'root',
// 密码
'password' => 'root',
// 端口
'hostport' => '3306',
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'table_',
// 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)
'deploy' => 0,
// 数据库读写是否分离 主从式有效
'rw_separate' => false,
// 读写分离后 主服务器数量
'master_num' => 1,
// 指定从服务器序号
'slave_no' => '',
// 是否严格检查字段是否存在
'fields_strict' => true,
// 是否需要断线重连
'break_reconnect' => false,
// 监听SQL
'trigger_sql' => true,
// 开启字段缓存
'fields_cache' => false,
],
],
];
<?php
return [
//是否开启Redis Session
'session_redis' => false,
//Session Redis (php.ini中session.auto_start设为0,否则无法正常使用Redis)
'session_redis_config' => [
'host' => '127.0.0.1', // 必选参数
'port' => 6379, // 必选参数
'auth' => '******', // 可选参数
'timeout' => 2, // 可选参数
'database' => 2, // 可选参数
'prefix' => 'session_' // 可选参数
]
];
<?php
//https://www.kancloud.cn/manual/think-template/1286403
return [
'view_path' => 'view', // 模板路径
'view_suffix' => 'php', // 默认模板文件后缀
'view_depr' => DIRECTORY_SEPARATOR,//模板文件分隔符
'cache_path' => 'temp', //模板缓存目录
'cache_suffix' => 'php', // 默认模板缓存后缀
'tpl_deny_func_list' => 'echo,exit', // 模板引擎禁用函数
'tpl_deny_php' => false, // 默认模板引擎是否禁用PHP原生代码
'tpl_begin' => '{', // 模板引擎普通标签开始标记
'tpl_end' => '}', // 模板引擎普通标签结束标记
'strip_space' => false, // 是否去除模板文件里面的html空格与换行
'tpl_cache' => false, // 是否开启模板编译缓存,设为false则每次都会重新编译
'compile_type' => 'file', // 模板编译类型
'cache_prefix' => '', // 模板缓存前缀标识,可以动态改变
'cache_time' => 0, // 模板缓存有效期 0 为永久,(以数字为值,单位:秒)
'layout_on' => false, // 布局模板开关
'layout_name' => 'layout', // 布局模板入口文件
'layout_item' => '{__CONTENT__}', // 布局模板的内容替换标识
'taglib_begin' => '{', // 标签库标签开始标记
'taglib_end' => '}', // 标签库标签结束标记
'taglib_load' => true, // 是否使用内置标签库之外的其它标签库,默认自动检测
'taglib_build_in' => 'cx', // 内置标签库名称(标签使用不必指定标签库名称),以逗号分隔 注意解析顺序
'taglib_pre_load' => '', // 需要额外加载的标签库(须指定标签库名称),多个以逗号分隔
'display_cache' => false, // 模板渲染缓存
'cache_id' => '', // 模板缓存ID
'tpl_replace_string' => [],
'tpl_var_identify' => 'array', // .语法变量识别,array|object|'', 为空时自动识别
'default_filter' => 'htmlentities', // 默认过滤方法 用于普通标签输出
];
<?php
return [
//协议
'listen' => 'http://0.0.0.0:8888',
//进程数
'worker_num' => 4,
//静态资源目录
'document_root' => 'public',
];
<?php
return [
//协议
'listen' => 'http://0.0.0.0:9529',
//进程数
'worker_num' => 4,
//静态资源目录
'document_root' => 'public',
//配置发送输出缓存区内存尺寸
'buffer_output_size'=>'32 * 1024 * 1024'
];
php zqphp swoole start
php zqphp swoole stop
以debug(调试)方式启动
php zqphp start
以daemon(守护进程)方式启动
php zqphp start -d
php zqphp stop
php zqphp restart
php zqphp reload
php zqphp status
php zqphp connections
zqphp\facade\Session
Session::set($key, $value = null);
//单个设置
Session::set('token','123456');
//多个设置
Session::set(['token'=>'123456','userid'=>8]);
Session::get($key = null, $default = null)
//获取整个Session数组
Session::get();
//获取Session数组的某一个值
Session::get('userid');
//获取Session数组的某一个值,如果Session数组中不包含这个值则返回null
//你也可以给get方法第二个参数传递一个默认值,如果Session数组中没找到对应值则返回默认值
Session::get('userid',1);
Session::delete($key = null)
//删除指定Session
Session::delete('user');
//删除多个Session
Session::delete(['userid','token']);
//删除全部Session
Session::delete();
Session::pull($key, $default = null)
Session::pull('userid');
Session::get('userid');
Session::delete('userid');
Session::has($key)
//userid不管有没值,只要存在就返回true,不存在返回false
Session::has('userid');
Session::sessionId()
zqphp\facade\Cookie
Cookie::set($key, $value = null, $maxAge = 0, $path = '', $domain = '', $secure = false, $only = false)
//单个设置(有效10秒)
Cookie::set('token','123456',10);
//多个设置
Cookie::set([['token','123456',10],['userid','8',30]]);
Cookie::get($key = null, $default = null)
//获取整个Cookie数组
Cookie::get();
//获取Cookie数组的某一个值
Cookie::get('userid');
//获取Cookie数组的某一个值,如果Cookie数组中不包含这个值则返回null
//你也可以给get方法第二个参数传递一个默认值,如果Cookie数组中没找到对应值则返回默认值
Cookie::get('userid',1);
Cookie::delete($key = null)
//删除指定Cookie
Cookie::delete('user');
//删除多个Cookie
Cookie::delete(['userid','token']);
//删除全部Cookie
Cookie::delete();
Cookie::pull($key, $default = null)
Cookie::pull('userid');
功能和以下代码相同
Cookie::get('userid');
Cookie::delete('userid');
Cookie::has($key)
//userid不管有没值,只要存在就返回true,不存在返回false
Cookie::has('userid');
zqphp\facade\Request
Request::getIp()
Request::getHost($type = false)
Request::get($key = null, $default = null)
//获取整个get数组
Request::get();
//获取get数组的某一个值
Request::get('id');
//获取get数组的某一个值,如果get数组中不包含这个值则返回null
//你也可以给get方法第二个参数传递一个默认值,如果get数组中没找到对应值则返回默认值
Request::get('id',1);
Request::post($key = null, $default = null)
//获取整个post数组
Request::post();
//获取get数组的某一个值
Request::post('id');
//获取post数组的某一个值,如果get数组中不包含这个值则返回null
//你也可以给post方法第二个参数传递一个默认值,如果post数组中没找到对应值则返回默认值
Request::post('id',1);
Request::getHeader($key = null, $default = null, $headData = [])
获取整个header数组
Request::getHeader();
获取header数组的某一个值 如果请求没有header参数则返回一个空的数组。注意所有key均为小写(分隔符号为-)
Request::getHeader('host');
如果header数组中不包含这个值则返回null。注意所有key均为小写。 与get方法一样,你也可以给header方法第二个参数传递一个默认值,如果header数组中没找到对应值则返回默认值。例如
Request::getHeader('host','localhost');
获取:$_SERVER['HTTP_X_REQUESTED_WITH']
使用:Request::getHeader('x-requested-with')
http://127.0.0.1:8080/user/get.php?uid=10&type=2
时将返回/user/get.php?uid=10&type=2
Request::getUri()
http://127.0.0.1:8080/user/get.php?uid=10&type=2
时将返回/user/get.php
Request::getPath()
http://127.0.0.1:8080/user/get.php?uid=10&type=2
时将返回uid=10&type=2
Request::getQueryString()
GET、POST、PUT、DELETE、OPTIONS、HEAD
中的一个Request::getMethod()
file_get_contents("php://input");
Request::getBody()
Request::getFile($key = null, $default = null)
获取整个上传文件数组
Request::getFile();
返回的文件格式类似:
array (
'avatar' => array (
'name' => '123.jpg',
'tmp_name' => '/tmp/workerman.upload.9hjR4w',
'size' => 1196127,
'error' => 0,
'type' => 'application/octet-stream',
),
'anotherfile' => array (
'name' => '456.txt',
'tmp_name' => '/tmp/workerman.upload.9sirSws',
'size' => 490,
'error' => 0,
'type' => 'text/plain',
)
)
其中:
获取特定上传文件
Request::getFile('avatar');
返回类似
array (
'name' => '123.jpg',
'tmp_name' => '/tmp/workerman.upload.9hjR4w',
'size' => 1196127,
'error' => 0,
'type' => 'application/octet-stream',
)
Request::getLocalIp()
http https
中的一个Request::getScheme()
Request::getProtocolVersion()
Request::getServer()
Request::isAjax()
Request::isPjax()
zqphp\facade\Response
@开头=配置目录,#开头=应用目录,~开头=启动目录
Response::sendFile($localfile, $mime = null)
输出Mp3文件,自动加上mime
Response::SendFile('/www/wwwroot/mp3.mp3');
输出Mp3文件,下载名为mp3.mp3
Response::SendFile(['/www/wwwroot/mp3.mp3','mp3.mp3']);
@开头=配置目录,#开头=应用目录,~开头=启动目录
Response::sendFileStream($localfile, $mime = null)
输出Mp3文件,自动加上mime
Response::sendFileStream('/www/wwwroot/mp3.mp3');
输出Mp3文件,下载名为mp3.mp3
Response::sendFileStream(['/www/wwwroot/mp3.mp3','mp3.mp3']);
Response::sendData($data, $mime)
Response::sendData('图片内容','jpg');
Response::sendData(['图片内容','下载名称'],'jpg');
Http
跳转Location
头进行发送302
临时跳转,传入301
表示永久跳转】Response::redirect($url, $code = 302)
Response::redirect("http://www.baidu.com/",301);
Response::head($name, $data = null, $head = [])
//单个设置
Response::SetHead('Content-Length',80);
//多个设置
Response::SetHead(['Content-Length'=>80,'Connection'=>'keep-alive']);
Response::status($key = 200)
Response::status(200);
功能和以下代码功能相同(主要为了兼职Worker,和后面的Swoole)
header("HTTP/1.1 200 OK");
Response::come($data, $status = 200, $header = [])
项目内不能使用:
echo 'Hello';
exit;
die('Hello');
这些使用Response::come('Hello');`代替
zqphp\Load
Load::getConfigPath()
Load::getAppPath()
Load::getRootPath()
Frame::filePath($file, $dir = null)
zqphp\extend\Frame
Frame::getMime($key)
Frame::getFileMime($file)
zqphp\facade\View
View::assign(array $vars = []);
View::assign(['name'=>'zqphp']);
View::fetch(string $template, array $vars = []);
View::assign('index',['name'=>'zqphp']);
View::display(string $content, array $vars = []);
//如果希望直接解析内容而不通过模板文件的话,可以使用display方法
$content = '{$name}-{$email}';
$temlate->display($content, ['name' => 'thinkphp', 'email' => 'thinkphp@qq.com']);
zqphp\facade\Db
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。