php - codeigniter:闭包表 - 添加后代

标签 php codeigniter hierarchical-data transitive-closure-table

我正在尝试添加一个新的后代,但很难实现它,它显示了一些错误,如果您能花时间回顾一下我迄今为止所做的事情,我将不胜感激。

这里

Controller

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>

谢谢。

错误

Message: Array to string conversion

最佳答案

您的模型不能称为“Closure”,因为这是 PHP 中的保留名称。将名称更改为其他名称,它应该可以工作。

关于php - codeigniter:闭包表 - 添加后代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47081049/

相关文章:

php - 通过 Ajax 从 Mysql 获取数据表内容

javascript - 按国家/地区代码隐藏 div

php - 如何在 smarty codeigniter 中获取基本 url

php - MySQL父->子查询

python - Pandas MultiIndex 中的重采样

php - 是否有任何 PHP 框架(例如 CodeIgniter)支持基于每个用户帐户的数据库连接以用于 Multi-Tenancy 数据库?

php - 如何为 PHP 文件设置 UTF-8 编码

php - Codeigniter foreach undefined variable

json - 如何使用Code Igniter REST_Controller定义内容类型

model-view-controller - 分层系统的MVC URL方案设计