Thinkphp5 assign 传递 " 时 ,前台收到的是 " 和ThinkPHP3.2不一样,3.2收到的是 ”,传递给js时

用的data.replace(new RegExp('"','g'),'"')替换回来
貌似不好,获取值的时候可以用 {$data.abc|raw} 解决传入参数"替换&quot问题
也就是如果前台传入的是json数据 后台用 { |raw}解决 Thinkphp5.1
在部分Base.php 控制器中 \think\Request::instance()->controller()根本调用不到
需要 \think\facade\Request::instance()->controller() 可以, 前台url链接指向其他控制器方法时可用
{foreach name="vo" item="val"}
<li id="{$val.title}">
    <a href=" {:url($val.model.'/'.$val.action)}">{$val.title}</a>
</li>
{/foreach}

  

当前台输出输出数据时

输出的效果是

网页源代码可以看到因果

想要的效果是

解决方式

浏览器开发者工具中

网页源代码中

总结:模板动态输出含标签的html代码,或者双引号时,默认输出结果会经过htmlentities()转义,结果不是我们想要的,解决办法时{XX|raw}

模板继承的时候第二种模板标签方式 replace="[XXX]" 不要用replace="{XXX}" 否则会意外多出 “/>

Thinkphp5.1用Model类时,return数据
在控制器dump返回的数据时显示是一个数组————坑
array_merge()总是提示不是数组
用var_dump()打印Model返回值时发现,那是一个对象
想要Model返回array对象增加一个->toArray()

Coin::where('userid',$data)->find()->toArray();

get与param区别

Thinkphp5.1遇到的坑

某两个相似的时间戳前台用,已提交issure,已改进 githubIssure  githubCode

输出

一个输出的是

有的输出就不正确,打印出变量查看时间戳是正确的

产看缓存中的输出

再追究

$time = 1508982277; //2017/10/26 9:44:37
var_dump(strtotime($time));
echo '<br>';
$time = 1508489607; //2017/10/20 16:53:27
var_dump(strtotime($time));

这结果!!

3.2是这么干的

模型关联删除问题

A hanMany B

    public function test()
{
$user = A::get(1);
echo '<pre>';
$temp = $user->products; var_dump($temp); //得到的是think\model\Collection对象
var_dump($user->products()->select()); //得到的是think\model\Collection对象,$user->products()得到的是hasMany对象
var_dump($user->products()->where('id', 28)->find()); //得到B对象

var_dump($user->products()->where('id', 28)->delete()); //数据库中数据已删除
var_dump($user->products()->select());  //id = 28 的数据已删除
var_dump($temp); //id = 28 的数据依旧存在 }
object(think\model\Collection)#99 (1) {
["items":protected]=>
array(3) {
[0]=>
object(app\user\model\ShopCar)#102 (2) {
["data"]=>
array(5) {
["id"]=>
int(27)
["产品id"]=>
int(2)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757081)
}
["relation"]=>
array(0) {
}
}
[1]=>
object(app\user\model\ShopCar)#101 (2) {
["data"]=>
array(5) {
["id"]=>
int(28)
["产品id"]=>
int(5)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757086)
}
["relation"]=>
array(0) {
}
}
[2]=>
object(app\user\model\ShopCar)#100 (2) {
["data"]=>
array(5) {
["id"]=>
int(29)
["产品id"]=>
int(6)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757861)
}
["relation"]=>
array(0) {
}
}
}
}
object(think\model\Collection)#95 (1) {
["items":protected]=>
array(3) {
[0]=>
object(app\user\model\ShopCar)#16 (2) {
["data"]=>
array(5) {
["id"]=>
int(27)
["产品id"]=>
int(2)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757081)
}
["relation"]=>
array(0) {
}
}
[1]=>
object(app\user\model\ShopCar)#96 (2) {
["data"]=>
array(5) {
["id"]=>
int(28)
["产品id"]=>
int(5)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757086)
}
["relation"]=>
array(0) {
}
}
[2]=>
object(app\user\model\ShopCar)#97 (2) {
["data"]=>
array(5) {
["id"]=>
int(29)
["产品id"]=>
int(6)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757861)
}
["relation"]=>
array(0) {
}
}
}
}
object(app\user\model\ShopCar)#16 (2) {
["data"]=>
array(5) {
["id"]=>
int(28)
["产品id"]=>
int(5)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757086)
}
["relation"]=>
array(0) {
}
}
int(1)
object(think\model\Collection)#87 (1) {
["items":protected]=>
array(2) {
[0]=>
object(app\user\model\ShopCar)#90 (2) {
["data"]=>
array(5) {
["id"]=>
int(27)
["产品id"]=>
int(2)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757081)
}
["relation"]=>
array(0) {
}
}
[1]=>
object(app\user\model\ShopCar)#89 (2) {
["data"]=>
array(5) {
["id"]=>
int(29)
["产品id"]=>
int(6)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757861)
}
["relation"]=>
array(0) {
}
}
}
}
object(think\model\Collection)#99 (1) {
["items":protected]=>
array(3) {
[0]=>
object(app\user\model\ShopCar)#102 (2) {
["data"]=>
array(5) {
["id"]=>
int(27)
["产品id"]=>
int(2)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757081)
}
["relation"]=>
array(0) {
}
}
[1]=>
object(app\user\model\ShopCar)#101 (2) {
["data"]=>
array(5) {
["id"]=>
int(28)
["产品id"]=>
int(5)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757086)
}
["relation"]=>
array(0) {
}
}
[2]=>
object(app\user\model\ShopCar)#100 (2) {
["data"]=>
array(5) {
["id"]=>
int(29)
["产品id"]=>
int(6)
["数量"]=>
int(1)
["编号"]=>
string(3) "gao"
["操作时间"]=>
int(1509757861)
}
["relation"]=>
array(0) {
}
}
}
}

模型可以直接当成普通方式查询数据,当join()后返回的不再是模型对象,而是array数据

ShopCar::where([['a.编号', '=', $userName], ['b.状态', '=', '使用']])->alias('a')
->join(['商城产品' => 'b'], 'a.产品id = b.id', 'LEFT')->column('a.产品id,a.数量,b.价格,b.pv,b.可订购数量,b.名称,b.重量,(b.可订购数量-a.数量) as numLeft', 'a.id');

行锁lock(true) 或者lock(false)什么也不做

ThinkPHP5.1

thinkphp\library\think\route\dispatch\Module.php P108 用到 is_callable()方法

        if (is_callable([$instance, $action])) {
// 执行操作方法
$call = [$instance, $action];
// 自动获取请求变量
$vars = $this->app->config('app.url_param_type')
? $this->app['request']->route()
: $this->app['request']->param();
} elseif (is_callable([$instance, '_empty'])) {
// 空操作
$call = [$instance, '_empty'];
$vars = [$actionName];
} else {
// 操作不存在
throw new HttpException(404, 'method not exists:' . get_class($instance) . '->' . $action . '()');
} $this->app['hook']->listen('action_begin', $call); return Container::getInstance()->invokeMethod($call, $vars);
}

但是当 $instance中有 __call 方法时,is_callable([$instance, $action]) 返回的总为true,需要注意,貌似Thinkphp5中反射导致的__call方法无效(个人临时理解)

colin 03-Oct-2010 08:30  //代码块来自PHP手册

 I haven't seen anyone note this before, but is_callable will correctly determine the existence of methods made with __call. The method_exists function will not.

 Example:
<?php class Test { public function testing($not = false) {
$not = $not ? 'true' : 'false';
echo "testing - not: $not<br/>";
} public function __call($name, $args) {
if(preg_match('/^not([A-Z]\w+)$/', $name, $matches)) {
$fn_name = strtolower($matches[1]);
if(method_exists($this, $fn_name)) {
$args[] = true; // add NOT boolean to args
return call_user_func_array(array($this, $matches[1]), $args);
}
}
die("No method with name: $name<br/>");
} } $t = new Test();
$t->testing();
$t->notTesting(); echo "exists: ".method_exists($t, 'notTesting').'<br/>';
echo "callable: ".is_callable(array($t, 'notTesting')); ?> Output: testing - not: false
testing - not: true
exists:
callable: 1

Thinphp5手册上说让用中文表名,中文字段,没有详细说明

个人可以想到的地方,

一是 pdo操作占位符的时候没特殊处理,

二是 中文表名得在model主动声明我这个model对应的是哪个表,英文表明一般可省略

三是Model返回的全是对象,字段实际上是对象的属性 ->id来调用,如果把id换成中文名称,怪怪的,还没见过谁的代码真用中文做变量。虽然也可以用 $obj['id’]查看属性的值

支付宝验证规则 邮箱/手机号/淘宝会员名
//        邮箱/手机号/淘宝会员名
'aliPay|c' => 'require|length:3,25',
'aliPay|d' => ['regex'=>'/^\w+((@\w{1,4}.\w{1,4})|(\w*))$/'],

觉得还比较理想

20171110

开发的项目中有这么个需求,对数据库中获取的数据进行加工。3.2的时候用的在控制器中获取数据库,然后用控制器中的方法修改数据。现在5.1尝试用模型的获取器。但是发现

中的$data是一个数组,也就是不能用模型关联中的数据。那可不行。

尝试后用$this对象访问便可

数据库/模型 返回类型

(new AModel)->saveAll($list) 返回的是插入的条数,ep:int(1)

最新文章

  1. Sprint2团队贡献分
  2. AngularJS-UI-Router
  3. Http概述(一)
  4. C#中WinForm程序退出方法技巧总结(转)
  5. LINUX第五次实验报告
  6. MVC字符串处理及MVC @RenderSection小计
  7. jquery iframe高度自适应
  8. linux下不能使用shutdown命令
  9. Java NIO UDP DEMO
  10. Tabhost嵌套以及Tab中多个Activity跳转的实现
  11. Android中各种Adapter的使用方法
  12. Python3 TA-Lib
  13. AbstractQueuedSynchronizer源码解读--续篇之Condition
  14. CentOS下如何查看并杀死僵尸进程
  15. jira发送邮件报错
  16. vue通过webpack打包后怎么运行
  17. IMP导入时的错误以及解决办法
  18. GaugeControl 之 DigitalGauge
  19. 安装Nginx并为node.js设置反向代理
  20. 使用SharedPreference保存用户数据的步骤

热门文章

  1. 生成gt数据出问题
  2. /^/m|/$/m|\b|\B|$&amp;|$`|$&#39;|变量捕获|()?|(?:pattern)|(?&lt;LABEL&gt;PATTERN)|$+{LABEL}|(|)|\g{LABEL}
  3. Electron的介绍
  4. c++ 指针数组,输入4个季度的花费,计算出总花费
  5. [bzoj]3436 小K的农场
  6. 【交互 细节题 思维题】cf1064E. Dwarves, Hats and Extrasensory Abilities
  7. [51nod] 1301 集合异或和
  8. hash 哈希查找复杂度为什么这么低?
  9. 单行代码实现xml转换成数组
  10. [译]The Python Tutorial#8. Errors and Exceptions