top-think / framework Goto Github PK
View Code? Open in Web Editor NEWThinkPHP Framework
Home Page: http://www.thinkphp.cn
License: Other
ThinkPHP Framework
Home Page: http://www.thinkphp.cn
License: Other
Input类 直接使用 $GLOBALS 来存储。
代码如下
RT.
如果不再重构, 我就把现有的代码结构改成新版的了
建议Model 等类库 进行拆分 如 laravel 中 composer require illuminate/database 一样
各种组件的拆分 对于我们会更好更自由的使用
因为在\library\traits\controller\Jump.php中的success方法和error方法用switch来判断请求类型,比较的值是小写,convention.php中default_ajax_return的默认值'JSON'是大写,这样会出错。
如果我用tp提供的常量写一个自定义的PUBLIC,他生成的是绝对路径。
然后在chrome里面测试会not allowed load local files。虽然有办法解决,但好麻烦
不能像tp3.2中一样提供相对路径吗
错误信息
[think\exception\ErrorException]
Undefined index: REQUEST_METHOD
错误日志
[error] [8]Undefined index: REQUEST_METHOD[D:\servers\vhosts\ThinkPHP\library\think\Request.php:413]
由于windows的cli下没有$_SERVER['REQUEST_METHOD']变量.
https://github.com/top-think/framework/blob/master/library/think/Request.php#L413
//原为
$method = isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD'];
//建议修改为
$method = isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : @$_SERVER['REQUEST_METHOD'];
或许你们有更好的解决办法.
@Moobusy @liu21st
图片传不上来,你们引入个jquery就会发现问题了,jquery最新版 2.2.3
希望解决下
\think\Url
第 155行
: if(strpos($domain, trim($domain_prefix, '*.')) !== false) {
报错:
[2] ErrorException in Url.php line 155
strpos(): Empty needle
https://github.com/top-think/framework/blob/master/library/think/template/taglib/Cx.php#L672
U 函数未实现,无法使用 url 函数。3.2 遗留问题?
thinkphp\library\think\console\output\Null.php 这里的这个类名 Null 在PHP7里面是系统保留关键字, 会提示错误,需要更改这个类名
------------PHP7提示错误信息如下:
Description Resource Path Location Type
Cannot use 'Null' as type name as it is reserved (since PHP7) Null.php /bjesc/trunk/thinkphp/library/think/console/output line 17 PHP 7 Problems
我是单独写的验证规则, 用 Validate 类来验证, 前端的字段比如是 userName, unique 规则是: unique:User,username, 此时
if (is_string($rule)) {
$rule = explode(',', $rule);
}
$db = Db::name($rule[0]);
$field = isset($rule[1]) ? $rule[1] : $field;
这里的 field 就是 username 了, 而 data 中的是 userName
Validate对象中, 自带的 unique
验证源码中获取数据使用是 Db::table($rule[0])
也就是说我在写 unique
验证的时候, 必须指定完整的数据表名称, 这样不太友好吧
这里应该用 Db::name($rule[0])
才对
RT.
我开启了如下二级域名部署, 并设置URL路由:
return [
"__domain__" => [
'baike' => 'index/baike',
],
"entry/:id" => "index/baike/entry",
];
此时使用域名 http://baike.xxx.com/entry/101
无法正常访问,
但取消二级域名部署后, 使用 http://www.xxx.com/entry/101
可以正常访问
通过router.php 作为入口文件开启 web 服务器后,Route 无法使用。
如下:
https://github.com/top-think/framework/blob/master/library/think/App.php#L343
只尝试进行了 $_SERVER['PATH_INFO']
的匹配判断。
实际上 php -S 不会有 $_SERVER['PATH_INFO']
.
Bug ?
`
{:$menu.parent.title | default = "无"} {$menu.group | default = "无"} `解析结果
`
Parse error: syntax error, unexpected 'default' (T_DEFAULT) in /wwwroot/newthink/runtime/temp/90b101dda1e9f74a4e15ff139d759c7e.php on line 155
0.039758s ShowPageTrace
[4] ErrorException in 90b101dda1e9f74a4e15ff139d759c7e.php line 155
syntax error, unexpected 'default' (T_DEFAULT)
Query.php
中的 parseWhereExp
方法中有如下一段代码:
if (is_string($field) && preg_match('/[,=\>\<\'\"\(`.\s]/', $field)) {
$where[] = ['exp', $field];
if (is_array($op)) {
// 参数绑定
$this->bind($op);
}
}
如果 $field
中存在 字符 .
, 则正则表达式就会生效
链表查询时, 使用 Db::name("table")->alias("t")->where("t.field", 1)->select();
就会出错, 解析出来的SQL 为 SELECT * FROM table t WHERE ( t.field )
在控制器里面调用助手函数redirect没有跳转,也没有报错。
redirect('http://www.baidu.com');
redirect(url('User/signin'));
以上都没有执行跳转,也没有报错,下面就可以正常跳转
$this->redirect('http://www.baidu.com');
$this->redirect('User/signin');
PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.dll, 9): no suitable image found. Did find: /Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20151012/php_pdo_mysql.dll: unknown file type, first eight bytes: 0x4D 0x5A 0x90 0x00 0x03 0x00 0x00 0x00
但是在thinkphp 3.2.3下无问题,同时刷新多次后该问题也会消失
在 \think\db\Query
文件的第 141
行 column
方法中:
$resultSet = $pdo->fetchAll(PDO::FETCH_ASSOC);
$fields = array_keys($resultSet[0]);
$count = count($fields);
$key1 = array_shift($fields);
$key2 = $fields ? array_shift($fields) : '';
如果获取的数据为空, 则这里代码会报错
protected $mapFields=[
'uid' =>'UcenterUser.uid',
'info_uid'=>'UcenterUserInfo.uid',
];
会报sql语句错误
经过排查 是因为 merge的save操作中的$data = $this->parseData($name, $this->data, true);后
把主键给弄丢了
Fatal error: Uncaught exception 'think\exception\ErrorException' with message 'mkdir(): Permission denied' in /home/test1net/test1.net/ThinkPHP/library/think/log/driver/File.php:43
Stack trace:
#0 [internal function]: think\Error::appError(2, 'mkdir(): Permis...', '/home/test1net...', 43, Array)
#1 /home/test1net/test1.net/ThinkPHP/library/think/log/driver/File.php(43): mkdir('./runtime/log/', 493, true)
#2 /home/test1net/test1.net/ThinkPHP/library/think/Log.php(95): think\log\driver\File->save(Array)
#3 /home/test1net/test1.net/ThinkPHP/library/think/Error.php(113): think\Log::save()
#4 [internal function]: think\Error::appShutdown()
#5 {main}
thrown in /home/test1net/test1.net/ThinkPHP/library/think/log/driver/File.php on line 43
RT.
app
目录下可能存在 common.php
, command.php
, config.php
, init.php
等文件
既然已经把 command.php
, config.php
统一到了 CONF_PATH 中, 为何还单独留着 common.php
在app
目录中.
有强迫症啊, 不想 app
目录下一堆散文件 😂
如果我想用户原来的单字母函数,是不是直接改helper下的函数的首字母
比如 congif => C
例如我有一组路由
Route::get('foo/bar/baz', '@aaa/bbb.CCC/index');
当我使用
Url::build('@aaa/bbb.CCC/index')
得出来的值是:/aaa/bbb.CCC/index
而不是:/foo/bar/baz
。
这种情况在RC2中并没有出现,最近升级到最新版本时才出现
开启二级域名部署后, 如果有设置二级域名指向到控制器的, 使用Url::build
生成的url存在问题
// URL二级域名部署
return [
'__domain__' => [
'www' => 'index',
'admin' => 'admin',
'news' => 'index/article'
],
];
假设我现在在二级域名 news
下, 使用 url
生成链接 Index/index@www
,
其结果为 http://www.xxx.com/home/index/index.html
但是我在 admin
域名下, 使用 url
生成链接 Index/index@www
,
起结果为 http://www.xxx.com/index/index.html
protected static function db()
if (!isset(self::$links[$model])) {
self::$links[$model] = Db::connect(static::$connection);
self::$links[$model]->setTable(static::$tableName);
$name = basename(str_replace('', '/', $model));
self::$links[$model]->name($name);
}
self::$links[$model] 多个model 共享了同一条链接
导致self::$links[$model]->name($name);会覆盖之前的name
public function scopeListInfo($query){
$query->field('UcenterUser.uid,username,avatar,company_name,idcard_auth,license_auth');
}
用命名范围只想调用几个字段 可依然会把表里所有字段都调用出来
SELECT UcenterUser.uid,username
,avatar
,company_name
,idcard_auth
,license_auth
,UcenterUser.uid AS uid,user_type
,username
,password
,weixin
,qq
,email
,mobile
,group
,vip
,avatar
,score
,sex
,age
,birthday
,login_total
,last_login_time
,last_login_ip
,reg_ip
,reg_type
,reg_time
,status
,UcenterUserInfo.uid AS info_uid,company_name
,province
,city
,area
,address
,idcard_auth
,license_auth
,idcard1
,idcard2
,license
,summary
FROM api_ucenter_user UcenterUser INNER JOIN api_ucenter_user_info UcenterUserInfo ON UcenterUserInfo.uid=UcenterUser.uid WHERE UcenterUser.uid = 1 LIMIT 1
http://ttst.2xso.com/158/T/ThinkPHP/ThinkPHP5/04/21/01/2.html
以上是发生错误的快照
`
$options = [
'type' => 'File', // 缓存类型为File
'expire'=> 0, // 缓存有效期为永久有效
'length'=> 3, // 缓存队列长度
'path' => APP_PATH.'runtime/cache/', // 指定缓存目录
];
S($options); // 缓存初始化
S('record_where',$where,3600); //这一行已经报错,$where的内容错误页面有的
`
这样实例化的,然后储存的,缓存文件已经生成了 ,看截图
http://www.thinkphp.cn/Uploads/editor/2016-04-22/5718fce5b5463.png
唯一验证这块 'mobile' =>'require|unique:api_ucenter_user',
查询的时候 我看sql老是select id from.... 实际上这个表的主键并不是id
并且我看手册上也没写明这块该怎么处理 试过下面的方式都不行
// 表示验证name字段的值是否在user表中唯一
'name' => 'unique:user',
// 验证其他字段
'name' => 'unique:user,account',
// 排除某个主键值
'name' => 'unique:user,account,10',
// 指定某个主键值排除
'name' => 'unique:user,account,10,user_id',
另外还有个不方便的地方 这里的表还得写表前缀 在做成通用产品的时候这块会很不方便
因为通用产品安装的时候会让用户在配置文件里自定义表前缀
TP5 里面优先加载了 composer的autoload
// 注册composer自动加载
self::registerComposerLoader();
有部分框架也使用了 与TP相冲突的函数
如illuminate\support\helpers.php 中的e() 相冲突
希望有新方案解决
1.composer 加载优先级 由我们自己控制
// 注册composer自动加载
self::registerComposerLoader();
2.使用 function_exists 避免冲突 在tp中 减少 E 函数的使用
think\db\connector\Pgsql 的 table_msg 问题为什么一直没有解决?
think\db\connector\Pgsql.php ,46行,
$result = $this->query('select fields_name as "field",fields_type as "type",fields_not_null as "null",fields_key_name as "key",fields_default as "default",fields_default as "extra" from table_msg(' . $tableName . ');');
SQL语句中table_msg函数并不存在,让人自己在pg里面定义这个函数不科学啊。
如题,使用模型验证时,传入指定的验证器,无法正常进行数据校验:
M("admin_users")->validate('AdminUsers')->create();
看了下源码,think\Model 中, validate 方法 没有在 $rule
为字符串时进行处理:
public function validate($rule = true, $msg = null)
{
if (true === $rule) {
$this->options['validate'] = $this->name;
} elseif (is_array($rule)) {
$this->options['validate'] = [
'rule' => $rule,
'msg' => is_array($msg) ? $msg : [],
];
} else {
// 新增代码
$this->options['validate'] = $rule;
}
return $this;
}
文件 /library/traits/think/Instance.php
中的 instance
方法建议加上如下注释
/**
* @param array $options
* @return static
*/
只有加了这个注释 PhpStorm
才能正常出现代码提示
在通过console命令行创建应用时,会创建出一个 .php 和 空的Index.php 文件, 这可能也是个问题吧,希望能得到解决。当前php版本 5.5.8.
现在我看见有个session的使用redis的类库,但具体操作控制器要用redis时,又需要我们自己去封装一个redis类库,如何一个控制器里面又需要操作redis又要操作session(用thinkphp自带的redis类库的话),会造成实例话两次redis对象,还有官方能改进自带的session操作redis吗,弄成单例模式最好了
我在配置中定义了如下路由:
return [
'route' => [
'letter-<first>' => [
'index/baike/lists',
[],
['first'=>'\w+']
],
'category/:name' => 'index/baike/category',
],
];
然后使用如下URL进行访问:
http://127.0.0.1/letter-a.html
http://127.0.0.1/category/分类
均无法正常访问到对应的控制器, 提示 illegal action name :.....
稍微看了下源码, 问题主要出在 think\Route::match()
方法中, 没有正确匹配.
假设我开启了如下二级域名部署
return [
'__domain__' => [
'www' => 'home', // 主站点
'api' => 'api', // API接口
'admin' => 'admin', // 管理后台
'news' => 'home/article', // 行情资讯
'baike' => 'home/baike', // 百科
],
];
我在 baike
域名下使用 U 函数生成 home 模块的 URL:
U("index/index@www");
理想结果应该是 http://www.t.com/index/index.html
但实际结果却是 http://www.t.com/home/index/index.html
仔细查看了一下源码, 在 think\Url::build()
函数中, 检测URL绑定的代码如下:
// 检测URL绑定
$type = Route::bind('type');
if ($type) {
$bind = Route::bind($type);
if (0 === strpos($url, $bind)) {
$url = substr($url, strlen($bind) + 1);
}
}
这个地方获取到的 $type
为当前子域名的绑定类型, 而不是我要解析的 www
子域名的绑定类型, 因此无法正常生成到对应子域名的URL
在 baike.t.com
域名下, 生成如下两个域名:
U("home/baike/index@baike"); // 输出的结果为 http://baike.t.com/index.html
U("home/baike/index@www"); // 输出的结果为 http://www.t.com/index.html
我需要动态修改模板路径来实现多套模板,但是并不能通过config
助手设置view_path
,而且在RC3之前view中的config
方法,在RC3里也见不到,fetch
方法的config
参数同样没有作用。
我看了一下,可能原因是模板驱动类里的parseTemplate
读取的view_path
是通过构造器传递进来的:
$depr = $this->config['view_depr'];
$template = str_replace(['/', ':'], $depr, $template);
if (strpos($template, '@')) {
list($module, $template) = explode('@', $template);
$path = APP_PATH . (APP_MULTI_MODULE ? $module . DS : '') . VIEW_LAYER . DS;
} else {
$path = $this->config['view_path'];
}
请教如何在Controller使用Model
浏览器 URL: AgentAccount/lists.html?page=1&aid=0&fullname=
分页的 URL: AgentAccount/lists.ht?page=2
lists.html 少了 ml 2个字符;
$this->baseUrl = rtrim($this->url(), '?' . $this->query()); 是由于此句代码造成的, 麻烦修复, 谢谢
Validate
类的checkItem
方法中的第 338
行
// 如果不是require 有数据才会行验证
if (0 === strpos($info, 'require') || !empty($value)) { // TODO 这里的 !empty($value)
// 验证类型
$callback = isset(self::$type[$type]) ? self::$type[$type] : [$this, $type];
// 验证数据
$result = call_user_func_array($callback, [$value, $rule, &$data, $field]);
} else {
$result = true;
}
在验证数据时, 使用的判断 !empty($value)
会将值为 0
的情况给忽略掉
比如要验证 gt:0
这里将始终跳过验证数据, 直接返回 true
https://github.com/top-think/framework/blob/master/library/think/View.php#L122
修改为如下,更清晰,效率更高
$content = strtr($content, $this->replace);
ref:
Response::instance()
方法的 @return
注释上加上 static
, 这样在 PhpStorm
中才能正常出现 Response
方法的代码提示, 即: /**
* 初始化
* @access public
* @param string $type 输出类型
* @return \think\Response|static
*/
\triaits\controller\Jump
中所有的方法都能使用 return
返回数据, 再由 \think\App
统一进行输出.success
和 error
方法中的Response::instance()->send($result, $type)
return Response::instance()->type($type)->data($result);
\triaits\controller\Jump
中 redirect
方法可以自动退出.Response::instance()->redirect($url, $params);
Response::instance()->isExit(true)->redirect($url, $params);
[info] [ CONFIG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/config.php
[info] [ CONFIG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/database.php
[info] [ CONFIG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/route.php
[info] [ CONFIG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/validate.php
[info] [ CONFIG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/auto.php
[info] [ LANG ] /Users/lewis/Desktop/htdocs/tp5.local/application/member/lang/zh-cn.php
$User->validate('Member')->create($data);
不能通过 指定 ‘Member’验证器调用,validate 只能用 true获取当前模型的验证器,或是用数组定义的验证
public function validate($rule = true, $msg = null)
{
if (true === $rule) {
$this->options['validate'] = $this->name;
} elseif (is_array($rule)) {
$this->options['validate'] = [
'rule' => $rule,
'msg' => is_array($msg) ? $msg : [],
];
}
return $this;
}
https://github.com/top-think/framework/blob/master/library/think/App.php#L272
进行了模块配置后加载了应用状态配置, 并没有体现出文档中 http://www.kancloud.cn/manual/thinkphp5/118024 所述的场景配置。
如下为简单代码片段:
if ($config['app_status']) {
$config = Config::load(APP_PATH. $config['app_status']. EXT);
}
放置到 274 行后即可保证文档、框架一致。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.