codeigniter: закрытие таблицы — добавить потомка

Я пытаюсь добавить нового потомка, но, сталкиваясь с трудностями при его достижении, он отображает некоторую ошибку. Был бы признателен, если бы вы уделили время рассмотрению того, что я сделал до сих пор.

Вот

контроллер

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>

Благодарю.

ошибка

Сообщение: преобразование массива в строку

0

Решение

Ваша модель не может называться «Закрытие», потому что это зарезервированное имя в PHP. Измените имя на другое, и оно должно работать.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector