我正在尝试创建一个与 CSV 一起使用的数据源。我正在关注这个例子
连接.php:
Connections::add('csv', [
'type' => 'file',
'adapter' => 'Csv',
]
);
应用程序/扩展/适配器/数据/源/文件/Csv.php
namespace app\extensions\adapter\data\source\file;
use lithium\core\Libraries;
class Csv extends \app\extensions\adapter\data\source\File {
public function __construct(array $config = []) {
$defaults = [
'delimiter' => ',',
'enclosure' => '\"',
'escape' => '\\',
'path' => Libraries::get(true, 'resources') . '/file/csv',
];
$config += $defaults;
parent::__construct($config);
}
public function read($query, array $options = array()) {
print_r($query);
die();
}
}
应用程序/扩展/适配器/数据/源/File.php
<?php
namespace app\extensions\adapter\data\source;
use lithium\core\Libraries;
class File extends \lithium\core\Object {
public function __construct(array $config = array()) {
$defaults = array(
'encoding' => 'UTF-8',
'path' => Libraries::get(true, 'resources') . '/file'
);
parent::__construct($config + $defaults);
}
}
?>
应用程序/模型/Importers.php
<?php
namespace app\models;
class Importers extends \lithium\data\Model {
protected $_meta = [
'connection' => 'csv',
];
}
?>
每当我Importers::find('all');
从控制器调用时,我都会收到错误消息:
Fatal error: Call to undefined method app\extensions\adapter\data\source\file\Csv::configureClass() in ...
如果我确实定义configureClass()
了,我会收到另一个错误说明enable()
未定义。不太确定我在这里做错了什么。