public function index_trans() { $line_items = array("0" => "line 1", "1" => "line 2", "2" => "line 3"); if (IS_POST) { $transDB = new \Think\Model(); $transDB->startTrans(); $title = array('title' => $_POST['title']); $header_result = $transDB->table('t_header')->add($title); if ($header_result) { $id = $transDB->table('t_header')->getLastInsID(); $line = array('line' => $_POST['selectedText'], 'header_id' => $id); $line_result = $transDB->table('t_detail')->add($line); if ($line_result) { $transDB->commit(); } else { $transDB->rollback(); } } else { $transDB->rollback(); } } $this->assign('line_items', $line_items); $this->display('transDemo'); }