i created this in one of function in the controller:
Configure::write('tmpTable', 'table-' . date("d-m-Y-H-i-s"));
after this i redirect to view and send a post request to same controller where i created a 'tmpTable' and when i tried to read it nothing was found, this Configure::read('tmpTable') just empty
i also tried to use $GLOBALS[] but it make same effect as Configure::read()
and also $this->Import->setSource() not saves table, i have always to re setup table to work with her
here is code:
function index() {
$tmp = Configure::read('tmpTable');
if ($tmp != '') {
$this->Import->setSource(Configure::read('tmpTable'));
$this->set('rows', $this->Import->find('all'));
}
}
function printdata() {
App::import('Vendor', 'parsecsv');
if ($this->request->is('POST') && !empty($this->request->data)) {
$csv = new parseCSV($this->request->data['Import']['CsvFile']['tmp_name'], ',');
$this->set('csv', $csv);
$this->createTable($csv);
}
}
function createTable($csv = null) {
Configure::write('tmpTable', 'table-' . date("d-m-Y-H-i-s"));
$sql = "CREATE TABLE IF NOT EXISTS `" . Configure::read('tmpTable') . "` (`id` int(11) NOT NULL AUTO_INCREMENT,";
foreach ($csv->titles as $value) {
$sql = $sql . " `" . $value . "` varchar(500) NULL,";
}
$sql = $sql . " PRIMARY KEY (`id`));";
$this->Import->query($sql);
}
function insertdata() {
$this->Import->setSource(Configure::read('tmpTable'));
if (!empty($this->request->data)) {
$this->Import->saveAll($this->request->data['Import']);
}
$this->redirect(array('action' => 'index'));
}