【问题标题】:cakephp-3.4 immutable http\request api APIcakephp-3.4 不可变 http\request api API
【发布时间】:2017-11-03 21:36:07
【问题描述】:

在 cakephp 3.3 中,我可以在控制器中使用这样的语句:

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

如何在 cake 3.4/3.5 中使用新的不可变 http\request api API 实现相同的效果?

【问题讨论】:

标签: php cakephp immutability cakephp-3.4


【解决方案1】:

因此,覆盖(甚至附加到)请求是一种非常糟糕的做法,因为这是客户端发送的内容 - 如果您仍然想这样做,可以使用反射来设置值...我提到这是不好的做法?

喜欢.. 非常糟糕的做法:)

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

我想我不必重复已经说过的内容,但是如果它可以为您节省版本之间升级的问题..这可能会解决它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-19
    • 2016-05-03
    • 1970-01-01
    • 2020-04-23
    • 1970-01-01
    • 2013-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多