doujiu4643 2017-11-03 21:36
浏览 48
已采纳

cakephp-3.4 immutable http equest api API

In cakephp 3.3 I could use statement like this in controller:

$this->request->data = array_merge($this->request->query,$this->request->data);

How can I achieve the same effect using new immutable httpequest api API i n cake 3.4/3.5?

  • 写回答

1条回答 默认 最新

  • douchilian1009 2017-11-13 15:35
    关注

    So it's quite bad practice to overwrite (or even append to) the request, since this is what the client has sent - if you really still want to go that way, one could use reflection to set the value... Did I mention this is bad practice?

    Like.. really bad practice :)

    $reflectionClass = new ReflectionObject($this->request);
    $reflectionProperty = $reflectionClass->getProperty('data');
    $reflectionProperty->setAccessible(true);
    $reflectionProperty->setValue($this->request, -YourNewArray-);
    

    I guess I don't have to repeat that what already has been said, but if it saves you the problem of upgrading between versions.. this might fix it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀