top-think / thinkphp Goto Github PK
View Code? Open in Web Editor NEWThinkPHP3.2 ——基于PHP5的简单快速的面向对象的PHP框架
Home Page: http://www.thinkphp.cn
ThinkPHP3.2 ——基于PHP5的简单快速的面向对象的PHP框架
Home Page: http://www.thinkphp.cn
thinkphp的库目录结构命名空间怎么改来改去的?不知道这是闹哪样。。。。
$this->goodsinfo = M('Good')->where($map)->select();
$this->response($this->goodsinfo,'JSON');
输出的JSON字符串在SAE上,最后面永远少一个']'字符
在本地有goodsinfo里数据少的时候 正常,但返回结果比较多时,也会出现这个情况
在ThinkPHP/Lib/Core/Db.class.php中逻辑判断似乎不完善
源码
// 如果配置为空,读取配置文件设置
if( C('DB_DSN') && 'pdo' != strtolower(C('DB_TYPE')) ) { // 如果设置了DB_DSN 则优先
$db_config = $this->parseDSN(C('DB_DSN'));
}else{
$db_config = array (
'dbms' => C('DB_TYPE'),
'username' => C('DB_USER'),
'password' => C('DB_PWD'),
'hostname' => C('DB_HOST'),
'hostport' => C('DB_PORT'),
'database' => C('DB_NAME'),
'dsn' => C('DB_DSN'),
'params' => C('DB_PARAMS'),
);
}
正确逻辑
// 如果配置为空,读取配置文件设置
if( C('DB_DSN') && 'pdo' == strtolower(C('DB_TYPE')) ) { // 如果设置了DB_DSN 则优先
$db_config = $this->parseDSN(C('DB_DSN'));
}else{
$db_config = array (
'dbms' => C('DB_TYPE'),
'username' => C('DB_USER'),
'password' => C('DB_PWD'),
'hostname' => C('DB_HOST'),
'hostport' => C('DB_PORT'),
'database' => C('DB_NAME'),
'dsn' => C('DB_DSN'),
'params' => C('DB_PARAMS'),
);
}
6月21日的提交你们将 C('CACHE_PATH',CACHE_PATH.GROUP_NAME.'/'); 这句移动到了 Dispatcher.class.php 中,但是前面有一句 if(defined('GROUP_NAME'))
这样导致了如下问题,如果项目配置常量中没有 GROUP_NAME,则会把编译模板生成到项目的根目录中。
解决方法:必须强制在入口文件中定义 GROUP_NAME 。
请修复
在无任何致命错误的情况下, Think::fatalError()仍然会被回调, 此时error_get_last()返回NULL. 似乎是由于register_shutdown_function()存在缺陷导致, 建议增加过滤逻辑.
已经再这里提交过了
我使用的是Pgsql数据库,在使用
create方法创建数据的时候,会自动转换我的值,
比如:这里是POST到服务器的数据。这里的isshow是y
{"name":"hunmareg","title":"\u7ba1\u7406","isshow":"y","status":"1","remark":"","navTabId":"Group","callbackType":"closeCurrent","_URL_":["Group","insert","navTabId","Group","callbackType","closeCurrent"]}
但最后生成的sql却是
(name,title,isshow,status,create_user,create_time,update_time,update_user,sort) VALUES ('hunmareg','\u7ba1\u7406',1,1,1,'now','epoch',0,0)
这里的isshow就是(int)1了。。。。
pqsql9.2提示如下:
ERROR column "isshow" is of type boolean but expression is of type integer at character 119
,是我的问题么?
暂时的解决办法:
/Extend/Driver/Db/DbPgsql.class.php 第300行加入
/**
* value分析
* @access protected
* @param mixed $value
* @return string
*/
protected function parseValue($value) {
if(is_string($value)) {
$value = '\''.$this->escapeString($value).'\'';
}elseif(isset($value[0]) && is_string($value[0]) && strtolower($value[0]) == 'exp'){
$value = $this->escapeString($value[1]);
}elseif(is_array($value)) {
$value = array_map(array($this, 'parseValue'),$value);
}elseif(is_bool($value)){
$value = $value ? 'TRUE' : 'FALSE'; //TOssP $value = $value ? '1' : '0';
}elseif(is_null($value)){
$value = 'null';
}
return $value;
}
如题
有配合使用的单元测试样例吗?
如果没有有相应的开发时间表吗?
谢谢~
ThinkException.class.php 63行: $traceInfo .= $t['class'].$t['type'].$t['function'].'(';
不是每一层调用都是方法调用。。。
栈中每一个函数调用都产生一个Notice级别的错误。
虽然这些notice在 Think::appError 中被忽略了,但是在有些情况下会产生奇怪的输出。
(忽略Notice错误对新手很不好。。。
应该改成
$traceInfo .= @$t['class'].@$t['type'].$t['function'].'(';
或者
$traceInfo .= (isset($t['class'])?$t['class'].$t['type']:'').$t['function'].'(';
最后还有…………明明叫做 _toString 却返回数组,各种意义上不科学……
ThinkPHP / Library / Think / Image / Driver / GIF.class.php
135行 $GIF_tim 未定义,貌似为$GIF_dly
原因系Model.class.php 946行和951行导致,望尽快修复。
public $viewFields = array(
'People' => array('*'),
'`Group`' => array('name' => 'group_name', 'level' => 'level', '_on' => 'People.group_id=Group.group_id'),
);
生成的SQL
SELECT
People.people_id AS people_id,
People.account AS account,
People.PASSWORD AS PASSWORD,
People.group_id AS group_id,
GROUP.NAME AS group_name,
GROUP.LEVEL AS LEVEL
FROM
bpi_people People
JOIN bpi_group GROUP ON People.group_id = GROUP.group_id
看到最后面的GROUP ON就知道问题出在哪里了
教程里是这样写的
U('Home/index'); 前面没有/,表示调用HOME分组下的INDEX模块
但我在独立分组中调用出现这样的结果,我在Company分组下调用
U('Home/index'); 得到的结果是 /index.php/company/home/index
使用U('/Home/Index'); 得到的是正确的结果 /index.php/home/index
是文档教程有遗漏错误, 还是功能有缺陷?
U方法现在只针对URL模式生成简单的URL规则,但对于自定义的URL_ROUTE_RULES无能为力,是否考虑针对普通正则生成的自定义路由进行反向解释,例如如下URL规则
return array(
'URL_MODEL'=>2,
'URL_ROUTE_RULES' =>array(
'/^c\/(\d+)\/g\/(\S+)$/' => 'cate/index?gid=:1&tag=:2',
)
);
/c/123/g/tagname 类似的网址重写成 /cate/index?gid=123&tag=tagname
但调用U方法 U("cate/index?gid=123&tag=tagname")
实际上只能生成/cate/index/gid/123/tag/tagname
而不是最精简的结果。
我通过修改U方法实现了以上简单的反向正则功能,但暂时不支持类似于news/:year/:month/:day
的反向解释
代码写在普通模式URL转换之后,代码如下:
if (C('URL_MODEL') == 2 && C('URL_ROUTER_ON')){ //存在路由时反向翻译
$routes = C('URL_ROUTE_RULES');
if (false === strpos('/', $url)) {
$url = implode($depr,array_reverse($var));
}
$_url=array_merge(parseUrl($url), $vars);
foreach ($routes as $rule=>$r_route){
$r_route = str_replace('/', $depr, $r_route);
$_route=parseUrl(str_replace(':', '~',$r_route));
if(url_compare($_url, $_route))break;
}
if(url_compare($_url, $_route)){
foreach ($_route as $key=>$val){
if($key==C('VAR_MODULE')||$key==C('VAR_ACTION'))continue;
if( preg_match("/~/",$val) ){
$rule=preg_replace("/(\(\\\[\w+]\+\))/",$_url[$key],$rule,1);
}
}
//去掉最后的"/"
$url = __APP__.'/'.ltrim(rtrim(trim($rule,'/'), '$'), '^');
$url = str_replace('\\', '', $url);
$flag = false;
}
}
在本地运行一切正常,生成的SQL也是正确的,但上传到SAE上生成的sql 多了两个字段
_autoinc
AS 1
,_pk
AS good_id
然后就报错了 Unknown column '_autoinc' in 'field list'
ThinkPHP 版本 3.1.2
前提:
'DATA_CACHE_TYPE'=>'Memcache', //默认缓存Memcache
"DB_SQL_BUILD_CACHE"=>true, //开启SQL缓存
'DB_SQL_BUILD_LENGTH' =>50, // SQL缓存的队列长度
'DB_SQL_BUILD_QUEUE' =>'file', // SQL缓存的队列存储方式
本地开启Memcahe服务端 ,浏览界面会报
[8] Undefined index: persistent E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 46 行.
[8] Undefined index: timeout E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 48 行.
[8] Undefined index: host E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 50 行.
[8] Undefined index: port E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 50 行.
[8] Undefined index: timeout E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 50 行.
[8] Memcache::connect() [memcache.connect]: Server (tcp 0) failed with: Failed to parse address "" (0) E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 50 行.
[2] Memcache::connect() [memcache.connect]: Can't connect to :0, Failed to parse address "" (0) E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 50 行.
[2] Memcache::set() [memcache.set]: Failed to extract 'connection' variable from object E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 78 行.
[2] Memcache::get() [memcache.get]: Failed to extract 'connection' variable from object E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 61 行.
[2] Memcache::set() [memcache.set]: Failed to extract 'connection' variable from object E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 78 行.
[2] Memcache::get() [memcache.get]: Failed to extract 'connection' variable from object E:\workspace\v5\ThinkPHP\Extend\Driver\Cache\CacheMemcache.class.php 第 61 行.
[2] Memcache::set() [memcache.set]: Failed to extract
查看代码发现开启SQL缓存后
Lib/Core/Db.class.php
if(isset($key)) { // 写入SQL创建缓存
S($key,$sql,array('expire'=>0,'length'=>C('DB_SQL_BUILD_LENGTH'),'queue'=>C('DB_SQL_BUILD_QUEUE')));
}
而在S方法中
static $cache = '';
if(is_array($options)){
// 缓存操作的同时初始化
$type = isset($options['type'])?$options['type']:'';
$cache = Cache::getInstance($type,$options);
}elseif(is_array($name)) { // 缓存初始化
$type = isset($name['type'])?$name['type']:'';
$cache = Cache::getInstance($type,$name);
return $cache;
}elseif(empty($cache)) { // 自动初始化
$cache = Cache::getInstance();
}
如果option 有值,直接传入Cache初始化参数中
CacheMemcache
if(empty($options)) {
$options = array (
'host' => C('MEMCACHE_HOST') ? C('MEMCACHE_HOST') : '127.0.0.1',
'port' => C('MEMCACHE_PORT') ? C('MEMCACHE_PORT') : 11211,
'timeout' => C('DATA_CACHE_TIMEOUT') ? C('DATA_CACHE_TIMEOUT') : false,
'persistent' => false,
);
}
$this->options = $options;
可见其判断 option不为空 ,就是用option
而上面的option里面 没有host,port,关键参数,导致memcache建立错误
我现在的临时改法是在CacheMemcache中 用 array_merge 合并参数
另外我还有个疑问
S 方法中使用的 static $cache ,会不会产生这样情况?
如果我第一次调用 S('key','value',array('type'=>'file');
第二次调用 S('key','value'); (不会使用我默认的Memcache),会使用CacheFile
只是初学,如果说错了,请指正。
graphviz是一个php扩展,分析性能的webgrind依赖这个扩展(linux - php5.4.13)。
我认为 functions.php 尽量不出现跟框架某个特定部分密切相关的东西(比如layout、load_ext_file ← 这货一辈子就被App::init调用一次有木有)
而是 halt、redirect、S 这类底层支持函数。
建议改成 View::layout ,因为调用layout函数会使View的行为发生改变。
现在输出属性如果之前碰到符号"{"的时候就不能正常解析,虽然打个空格就可以了,但是还是属于bug的吧。
提示:The MySQL server is running with the --read-only option so it cannot execute this statement [ SQL语句 ] : UPDATE log SET value = value + 1 WHERE id = 1
MySQL服务器正在运行 - 只读选项,所以它不能执行该语句
调试模式下,提示。
http://1.xyapi.sinaapp.com/Api/?use=test&key=test&type=ping
非调试模式下mysql也有错
http://2.dyapi.sinaapp.com/Api/?use=test&key=test&type=online
(下面的错误提示)
如题
开启分组、子域名部署、没有定义路由、URL不去分大小写
U('Group/Action/Method')
输出
/action/Method
(/index.php/action/Method ; /index.php?s=/action/Method)
Group部分被忽略了
当'TMPL_FILE_DEPR' => '_' 时,在模板中包含文件会包含不上
这样怕是要给没有使用表前缀的朋友的无缝升级带来一定的麻烦!
Table 'app_xyapi.think_log' doesn't exist [ SQL语句 ] : SHOW COLUMNS FROM think_log
这种是什么情况?要创建一个think_log
数据库吗?求解决
在config里面设置APP_DEBUG和URL_404_REDIRECT的时候,
发现无论APP_DEBUG是true还是false,都是抛出异常,而指定的404页面无效。
代码:APP_DEBUG && throw_exception($msg);
改为:C('APP_DEBUG') && throw_exception($msg);
php 5.5 以后不支持 在 preg_replace 中使用 e 正则表达式修饰符.
模板解析会导致连接重置
假如在Action中有assign两个变量,分别是a和b
那么在模版中 应该用{$a} 和{$b}来引用这两个变量
但是,当在{$a}所在的行前面有 { 的时候,模版将不把{$a}解析
举个例子:
jQuery.get('url', {'a':{$a}, 'b':{$b}}, function(data){}, "json");
这种情况{$a}将不会解析,而是直接输出字符串{$a}
但是将其与前一个 { 换行便可工作
jQuery.get('url', {
'a':{$a}, 'b':{$b}}, function(data){}, "json");
When use thinkphp group module with ThinkTemplate, it works fine.
But when use smarty as replacement, it can not work as follow:
exception 'SmartyException' with message 'Unable to load template file 'Index/index.html'' in D:\www\ThinkPHP\Extend\Vendor\Smarty\sysplugins\smarty_internal_templatebase.php:127 Stack trace: #0
I check git lastest thinkphp core file, but still have that problem, can you check whether check out your lastest file to git server? or never slove that problem, please tell me when you slove that issue,thanks . my email: [email protected]
程序
var_export($_POST['json']);
var_export(I('post.json'));
输出
array (
0 =>
array (
'id' => '',
'name' => 'xxxxxxxxxxx',
'auth' =>
array (
0 => 'del_self',
),
),
1 =>
array (
'id' => '',
'name' => 'qqqqqq',
'auth' =>
array (
0 => 'auth',
1 => 'add_self',
),
),
2 =>
array (
'name' => '',
),
)
array (
0 => '',
1 => '',
2 => '',
)
为什么去掉呢?是性能问题还是?
我直接改源码改回来了。
https://github.com/burugo/thinkphp/commit/c4f647cc269f69e3f87cd1361e184c77e4415b0f
如果把RelationModel.class.php的180行
原来的:
$sql = "SELECT b.{$mappingFields} FROM {$mappingRelationTable} AS a, ".$model->getTableName()." AS b WHERE a.{$mappingRelationFk} = b.{$model->getPk()} AND a.{$mappingCondition}";
改为:
$sql = "SELECT {$mappingFields} FROM {$mappingRelationTable} AS a, ".$model->getTableName()." AS b WHERE a.{$mappingRelationFk} = b.{$model->getPk()} AND a.{$mappingCondition}";
自己定义$mappingFields来查询那个表那个字段。
如题,因为如果
$password = NULL;
$data = array(
'username' => 'test',
'password' => $password,
);
上述情况,password就能逃过检查,但实际上传给create的值是有password的,这和原功能描述 存在该字段就验证 不符,。。是否使用array_key_exists更妥当?
$model->startTrans();
$data = $model->lock(true)->where('id=' . $dataId)->find();
...
关键代码如下:
public function query($str) {
$this->initConnect(false);
if ( !$this->_linkID ) return false;
...
看了Image.class.php 和相关Driver里对图片文件的操作都是基与本地文件的,在SAE上无法正常工作
Line:275 $val['dey']=> $val['key']
出现的问题: pdo链接无法获取主键, 关联模型定义foreign_key 不起作用
mysql驱动,Model连贯操作能否支持where上可以使用use index、force index等
如:SELECT * FROM table
FORCE INDEX(index) WHERE id=123
可以用连贯操作来生成
N函数(69行)和C函数(370行)中各用了两次cache函数
Image / Driver / Imagick.class.php
Imagick自定义类和全局类的冲突没处理好
$model->token(false)->create(); 会执行多个模型中定义的自动验证吗
ThinkPHP2是直接通过修改源代码让其支持ActionChain的
3有什么通过扩展的办法让其支持ActionChain么?
看了下App::exec方法貌似给写死了。
普通部署正常,在SAE下,非调试模式,无任何输错,调试模式时提示错误!
Fatal_error: print_r() [ref.outcontrol]: Cannot use output buffering in output buffering display handlers in ThinkPHP/Extend/Engine/Sae/Common/common.php on line 613
求解,前一个版本在SAE下也正常,本地和普通服务器也正常。
ThinkPHP/Lib/Core/Dispatcher.class.php第109行
$var[C('VAR_GROUP')] = in_array(strtolower($paths[0]),explode(',',strtolower(C('APP_GROUP_LIST'))))? array_shift($paths) : '';
$paths数组只有两个值而且$paths[0]存在于APP_GROUP_LIST的时候,会被误判为分组。例如:
假设我默认分组是Index,我要调用Index模块的add方法。
http://localhost/index.php/Index/add 这个URL是正确的
但是却是访问到了Index分组的add模块的index方法,希望能修正。
同时还有一个问题是,当我的URL_MODE = 0的时候,ACTION返回的格式并不是/index.php?g=xx&m=xx&a=xx这样的格式,而是index.php/xx/xx/xx
如题。
对于从 CodeIgniter 等框架转过来的同学来说,对于控制器的命名居然是用 控制器内的方法(动作)来命名,引起了不少的混淆。且 MVC 命名规则也是惯例。特提此建议,考虑一下?
@liu21st @luofei614 @Aoiujz
更新 TagLib 标签属性分析出错
Composer 是php的包依赖管理 https://github.com/composer/composer
Composer里面现在已经有很多包了,里面很多框架加入了。
是否考虑将TP和很多各种TP的插件都引入Composer...不知道成本大否..
这里 Packagist submit package
4、直接使用函数
{|function} 例如:{|time}
这种方式有问题。
增加时出现了这样一条语句, 清空了中间表, 不知如何解决?
SQL: DELETE FROM 中间表
写入的语句是这样的:
$this->model->relation(true)->add($_POST);
$_POST 数据编码成JSON如下,
{"name":"\u516b\u8fbe\u5cad\u957f\u57ce-\u5b9a\u96751\u65e5\u6e38\uff1c\u8d60\u5bcc\u6765\u5bab\u6e29\u6cc9\uff0c\u53e4\u795e\u9053\u5916\u666f\uff1e ","title":"\u8d60\u9001\u54c1\u5c1d\u8001\u5317\u4eac\u7279\u8272\u9910\uff0c\u54c1\u5c1d\u5730\u9053\u5317\u4eac\u5473\u513f\u3002","Categories":[{"id":"5"},{"id":"88"},{"id":"89"}],"Distributors":[{"id":"1"},{"id":"2"},{"id":"7"},{"id":"11"},{"id":"15"},{"id":"17"}],"Groups":[{"id":"12"},{"id":"13"},{"id":"15"},{"id":"17"},{"id":"19"}],"uid":"1","suid":"1","emergency_phone":"13468843724","reception":"\u5408\u80a5","serial_number":"864","is_direct_sale":"1","is_distribute_sale":"1","single_room_spread":"50","refer_price":"30","Prices":{"1":{"name":"\u6210\u4eba\u4ef7","price":"1000","peer_price":"900","cost":"800","description":"\u6210\u4eba\u4ef7","reserve_seat":"0","is_shuttle_fare":"1","available_to_distributor":"1"}},"department_transportation":"\u98de\u673a","renturn_transportation":"\u98de\u673a","Places":{"1":{"place":"\u9526\u6c5f\u5927\u53a6","time":"10:00","price":"10"}},"group_start_date":"2013-12-24","group_state":"1","group_end_date":"","departure_time":"06:00","return_time":"04:00","sale_inadvance":"10","duration":"1","max_number":"0","min_number":"1","begin":"10\u67081-4\u65e5\u5929\u5929\u53d1\u56e2","cancle_rule":"\u5927\u4e8e24\u5c0f\u65f6\u9000\u56e2\u4e0d\u6536\u8d39\uff0c24\u5c0f\u65f6\u5185\u6536\u53d610%\u56e2\u8d39 ","insurance":"\u65c5\u6e38\u610f\u5916\u9669 \u65c5\u884c\u793e\u8d23\u4efb\u9669","description":"","schedule":"","service":"","tips":"","remark":"","logo_image":"","seo_title":"","seo_keywords":"","seo_description":""}
当前版本的模版继承与include都不支持跨分组调用,还是我没看仔细文档?
3.2版本是否还打算加入对RESTful的支持?看README文件里面写的有,但是未找到该库,是否有时间计划?
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.