-
Notifications
You must be signed in to change notification settings - Fork 2
/
README
68 lines (45 loc) · 1.48 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
CSV Datasource for reading your CSV files
Originally based on work of Siegfried Hirsch (Siegfried):
http://bakery.cakephp.org/articles/view/csv-datasource-for-reading-your-csv-filesi
Licensed under The MIT License
Redistributions of files must retain the above copyright notice.
Example:
1. Copy the data source file on your models/datasources/ directory
/app/models/datasources/csv_sourse.php
2. Setup your database connection:
class DATABASE_CONFIG {
public $csvFileConfig = array(
'datasource' => 'csv',
'path' => "/path/to/your/file.csv",
'header_row' => 7 // It use this row as header and start to read data from next row... previous rows will be ignored
);
public $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'user',
'password' => 'password',
'database' => 'test_database_name',
'prefix' => ''
);
}
3. Setup your model
<?php
class MyModel extends AppModel {
public $name = 'MyModel';
public $useDbConfig = 'csvFileConfig';
public $useTable = false;
}
?>
4. Now you can retrive the csv data from controller
<?php
class ExampleController extends AppController {
public $name = 'Example';
public $uses = array('MyModel');
function index() {
//retrive rows with the id bethween 11 and 20
$csvData = $this->MyModel->find('all', array('page' => 2, 'limit' => 10));
$this->set('csvData', $csvData);
}
}
?>