【问题标题】:How to get params from query object in CakePHP 3如何从 CakePHP 3 中的查询对象获取参数
【发布时间】:2018-07-14 02:18:55
【问题描述】:

如何从 CakePHP 3 中的查询对象中获取“参数”?

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

当我调试 $response 时,我得到了这个 (:

// ...
'(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]
    ]
],
// ...

我想知道:c2 的值是什么,但我似乎无法让params 进行调试。

我试过这些:

\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());

但没有任何工作。

【问题讨论】:

    标签: php object cakephp cakephp-3.x cakephp-3.4


    【解决方案1】:

    通过增加调试深度,我能够看到其他信息,包括 :c2 的值

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

    【讨论】:

      【解决方案2】:

      您应该可以通过$response->valueBinder()->bindings() 获得它们。

      【讨论】:

        【解决方案3】:

        你可以使用__debugInfo()方法:

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

        【讨论】:

          猜你喜欢
          • 2018-09-04
          • 1970-01-01
          • 1970-01-01
          • 2023-03-18
          • 2017-05-07
          • 2015-06-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多