我正在尝试添加一个新的后代,但在实现它时遇到困难,它会显示一些错误,如果您能花时间回顾一下我到目前为止所做的事情,将不胜感激。
这里是
控制器
public function index() {
$this->load->view('closure_view');
}
public function add() {
$add_new = array(
'ancestor' => $this->input->post('ancestor'),
'descendant' => $this->input->post('descendant'),
'lvl' => $this->input->post('lvl'),
'id' => $this->input->post('id')
);
$cust_id = $this->closure->add($add_new);
redirect('http://localhost/kgmerchant/index.php/welcome');
}
模型
public $table;
public $closure_table = 'closures';
public function __construct($table_name = NULL, $closure_table = NULL){
parent::__construct();
$this->table = $table_name;
if ($closure_table !== NULL) {
$this->closure_table = $closure_table;
}
}
public function add($node_id, $target_id = 0) {
$sql = 'SELECT ancestor, '.$node_id.', lvl+1
FROM '.$this->closure_table.'
WHERE descendant = '.$target_id.'
UNION
SELECT '.$node_id.','.$node_id.',0';
$query = 'INSERT INTO '.$this->closure_table.' (ancestor, descendant, lvl) ('.$sql.')';
$result = $this->db->query($query);
return $result;
}
看法
<form name="home" method="post" action="<?php echo base_url().'index.php/home/add' ?>" >
<input placeholder="ancestor" type="text" name="ancestor" required/>
<input placeholder="descendant" type="text" name="descendant" required/>
<input placeholder="lvl" type="text" name="lvl" required />
<input placeholder="id" type="hidden" name="id" value="" />
<input type="submit" value="Okay" />
</form>
谢谢。
错误
消息:数组到字符串的转换