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 >
    <a href=" {:url($val.model.'/'.$val.action)}">{$val.title}</a>
    </li>
{/foreach}

  

当前台输出输出数据时

ThinkPHP5杂技(一)

输出的效果是

ThinkPHP5杂技(一)

ThinkPHP5杂技(一)

网页源代码可以看到因果

ThinkPHP5杂技(一)

想要的效果是

ThinkPHP5杂技(一)

解决方式

ThinkPHP5杂技(一)

浏览器开发者工具中

ThinkPHP5杂技(一)

网页源代码中

ThinkPHP5杂技(一)

 

总结:模板动态输出含标签的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杂技(一)

 

ThinkPHP5杂技(一)

 

Thinkphp5.1遇到的坑

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

ThinkPHP5杂技(一)

输出

一个输出的是

ThinkPHP5杂技(一)

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

产看缓存中的输出

ThinkPHP5杂技(一)

再追究

$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));

ThinkPHP5杂技(一)

这结果!!

3.2是这么干的

ThinkPHP5杂技(一)

 

模型关联删除问题

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) {
      }
    }
  }
}
View Code

相关文章:

  • 2021-12-31
  • 2021-04-14
  • 2021-08-06
  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-12-04
  • 2021-08-27
  • 2021-07-08
相关资源
相似解决方案