我正在尝试按照Creating Data Sources覆盖lithium\data\source\Http::read()
。这是我在How do I submit POST for cURL in Lithium中遇到问题的结果。
我现在有这样的事情:
<?php
namespace li3_tr42Auth\extensions\adapter\data\source\http;
class TR42 extends \lithium\data\source\Http {
protected $_classes = [
// unlike in the "Creating Data Sources" doc, I had to add the 'schema' key
// or I get an error when 'Libraries' tries to instantiate it.
'schema' => 'lithium\data\DocumentSchema',
'service' => 'lithium\net\http\Service',
'entity' => 'lithium\data\entity\Document',
'set' => 'lithium\data\collection\DocumentSet'
];
public function read($query, array $options = []) {
$params = $query->export($this, ['keys' => ['source', 'conditions']]);
$source = Inflector::camelize($params['source']);
$model = Libraries::locate('models', $source);
.
.
.
$decoded = $this->decode($response);
/** at this point, $decoded contains an associative array like:
* Array(
* [id] => 42,
* [name] => Housni,
* [status] => 1,
* [country] => Colombo, Sri Lanka
* )
*/
return $model::create($decoded, ['exists' => true]);
}
}
?>
如果我不使用item()
,任何finder都会按原样返回数组。
如果我使用item()
,我只会得到数组的第一个值42
,在这种情况下。
知道我在这里做错了吗?
更新
事实证明,只有find('first')
导致上述问题。
正如预期的那样,使用find('all')
返回一个对象。
不太清楚如何解决这个问题。
更新#2
我使用新的返回代码更新了上面的read()
代码。
如果我在从read()
返回之前显示结果,我会看到一个正确的Document
对象。看起来find()
方法正在发生一些事情。顺便说一句,我没有为模型运行任何过滤器。知道如何调试这个吗?
答案 0 :(得分:1)
item()
不存在anymore
您只需要用YourModel::create($decoded, ['exists' => true]);
请在手动仓库中打开一个问题来更新这部分文档; - )