我正在使用CodeIgniter开始游戏,但是我遇到了一个问题-我想从数据库中下载产品的ID-以便将其传递到URL地址:
我设法做到了这样:
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;
}
}
我的控制器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);
}
}
我的模型domains_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');
}
}
我的控制器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 ) . '}';
}
}