How to get params from query object in CakePHP 3

不羁的心 提交于 2020-01-16 19:36:26

问题


How do I get the 'params' from a query object in CakePHP 3?

$response = $this->getTable()->find();
// there are beforeFinds...etc that make this more complex

When I debug the $response, I get this (:

// ...
'(help)' => 'This is a Query object, to get the results execute or iterate it.',
'sql' => 'SELECT .... WHERE ... article_id = :c2',
'params' => [
    ':c0' => [
        [maximum depth reached]
    ],
    ':c1' => [
        [maximum depth reached]
    ],
    ':c2' => [
        [maximum depth reached]
    ]
],
// ...

I'd like to know what the value of :c2 is, but I can't seem to get the params to debug.

I've tried these:

\Cake\Error\Debugger::log($response->params);
\Cake\Error\Debugger::log($response->params());
\Cake\Error\Debugger::log($response['params']);
\Cake\Error\Debugger::log($response->getParams());
\Cake\Error\Debugger::log($response->getQueryParams());

But none work.


回答1:


By increasing the depth of the debug, I was able to see dditional information, including the values of the :c2

\Cake\Error\Debugger::log($response, 'debug', 4); // default depth is 3



回答2:


You should be able to get them via $response->valueBinder()->bindings().




回答3:


You can use __debugInfo() method:

$result = $this->Pages->find()->where(['is_public' => 1]);

dd($result->__debugInfo()['params']);


来源:https://stackoverflow.com/questions/48602025/how-to-get-params-from-query-object-in-cakephp-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!