codeigniter:关闭表-添加后代 [英] codeigniter: closure table - add descendant

查看:60
本文介绍了codeigniter:关闭表-添加后代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加一个新的后代,但是由于实现困难,它会显示一些错误,如果您能抽出时间来回顾我到目前为止所做的一切,将不胜感激.

I'm trying to add a new descendant, but having difficulties achieving it, it displays some error, Would be grateful if you could take time to review what I've done thus far.

这是

控制器

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

推荐答案

您的模型不能称为关闭",因为这是PHP中的保留名称.将名称更改为其他名称,它应该可以使用.

Your model can't be called "Closure" because that's a reserved name in PHP. Change the name to something else and it should work.

这篇关于codeigniter:关闭表-添加后代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆