在cakephp中相当于MYSQL'SELECT INTO'

时间:2017-09-07 10:27:01

标签: cakephp

我有一张临时表。称之为table1。我想将table1中的每一行复制到table2。我相信SELECT INTO可以在mysql中做到这一点。

现在我想知道如何用cakephp2.4完成这个任务。

1 个答案:

答案 0 :(得分:0)

$this->loadModel('Table1');
    $find_new=$this->Table1->find('all');
    $this->set('find_new', $find_new);
    foreach($find_new as $find_new):
    $this->Tabel2->create();
    $this->request->data['Table2']['field1']=$find_new['Table1']['field1'];
    $this->request->data['Table2']['field2']=$find_new['Table1']['field2'];
    $this->request->data['Table2']['field3']=$find_new['Table1']['field3'];
    $this->Table2->save($this->request->data);
    endforeach;
    return $this->redirect($this->referer());