问题
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