0

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'));
}
  • Why dont you add constant in core.php ? – Moyed Ansari Oct 22 '13 at 08:44
  • in my case it's always changing, i need global dynamic variable, i don't need constant – user2440002 Oct 22 '13 at 08:53
  • 1
    [`Configure::write()`](http://book.cakephp.org/2.0/en/development/configuration.html#configure-class) values do not persist between requests, it's a per-request storage. If you want to transfer data between requests, then use [`Configure::store()`](http://book.cakephp.org/2.0/en/development/configuration.html#storing-runtime-configuration), use the [session](http://book.cakephp.org/2.0/en/core-libraries/components/sessions.html), or even pass the values via `POST` or `GET` data – ndm Oct 22 '13 at 09:22
  • Also, you might want to escape your values you are inserting into the query. Because if the user somehow manages to change the session variables, you have a securityhole which you will regret. – Jelmer Oct 23 '13 at 08:23

0 Answers0