Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库到URL的ID_Php_Codeigniter 3 - Fatal编程技术网

Php 从数据库到URL的ID

Php 从数据库到URL的ID,php,codeigniter-3,Php,Codeigniter 3,我正在使用CodeIgniter开始我的游戏,我有一个问题-我想从数据库下载产品的ID-以便将其传递到URL地址: 我设法做到了这样: http://localhost/seo2/api/admin/domains/notes/{{domainID}} http://localhost/seo2/api/admin/domains/{{domainID}}/notes 我想要这样的东西: http://localhost/seo2/api/admin/domains/notes/{{doma

我正在使用CodeIgniter开始我的游戏,我有一个问题-我想从数据库下载产品的ID-以便将其传递到URL地址:

我设法做到了这样:

http://localhost/seo2/api/admin/domains/notes/{{domainID}}
http://localhost/seo2/api/admin/domains/{{domainID}}/notes
我想要这样的东西:

http://localhost/seo2/api/admin/domains/notes/{{domainID}}
http://localhost/seo2/api/admin/domains/{{domainID}}/notes
我的模型-notes-model.php

class notes_model extends CI_Model {

    public function get( $id = false)
    {
        if ( $id == false ) {
            $q = $this->db->get('notes');
            $q = $q->result();
        }
        else{
            $this->db->where('id', $id);
            $q = $this->db->get('notes');
            $q = $q->row();
        }
        return $q;
    }

    public function update($note)
    {
        $this->db->where('id', $note['id'] );
        $this->db->update('notes', $note);
    }

    public function create($note)
    {

        $this->db->insert('notes', $note);

    }

    public function delete($note)
    {
        $this->db->where('id', $note['id'] );
        $this->db->delete('notes');
    }

    public function get_by_domain_id($id)
    {
        $this->db->where('id_domain_rel', $id);
        $q = $this->db->get('notes');
        $q = $q->result();

        return $q;
    }

}
My controller notes.php:

class notes extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $post = file_get_contents('php://input');
        $_POST = json_decode($post,true);
        $this->load->model('admin/notes_model');
    }


    public function get($id = false)
    {
        $result = $this->notes_model->get($id);
        echo '{"records":' . json_encode( $result ) . '}';
    }



    public function update()
    {
        $note = $this->input->post('note');
        $this->notes_model->update($note);
    }

    public function create()
    {
        $note = $this->input->post('note');
        $this->notes_model->create($note);
    }

    public function delete()
    {
        $note = $this->input->post('note');
        $this->notes_model->delete($note);
    }
}
我的模型域\u model.php:

class domains_model extends CI_Model {


    public function get( $id = false)
    {
        if ( $id == false ) {
            $q = $this->db->get('domains');
            $q = $q->result();
        }
        else{
            $this->db->where('id', $id);
            $q = $this->db->get('domains');
            $q = $q->row();
        }
        return $q;
    }

    public function update($domain)
    {
        $this->db->where('id', $domain['id'] );
        $this->db->update('domains', $domain);
    }

    public function create($domain)
    {
        $this->db->insert('domains', $domain);
    }

    public function delete($domain)
    {
        $this->db->where('id', $domain['id'] );
        $this->db->delete('domains');
    }

}
My controller domains.php

class domains extends CI_Controller {

    public function __construct()
    {
        parent::__construct();

        $post = file_get_contents('php://input');
        $_POST = json_decode($post,true);
        $this->load->model('admin/domains_model');
    }

    public function get($id = false)
    {
        $result = $this->domains_model->get($id);
        echo '{"records":' . json_encode( $result ) . '}';
    }

    public function update()
    {
        $domain = $this->input->post('domain');
        $this->domains_model->update($domain);
    }

    public function create()
    {
        $domain = $this->input->post('domain');
        $this->domains_model->create($domain);
    }

    public function delete()
    {
        $domain = $this->input->post('domain');
        $this->domains_model->delete($domain);
    }

    public function notes($id)
    {
        $this->load->model('admin/notes_model');
        $result = $this->notes_model->get_by_domain_id($id);
        echo '{"records":' . json_encode( $result ) . '}';
    }
}

不确定你到底在问什么。你有没有尝试过解决你的问题的方法?将失败尝试的代码和收到的结果/错误放在URL中是否要传递id?@suresh是的,URL是按照上面显示的方式生成的。-查找URL-