I am starting my game with CodeIgniter and I have a problem - I would like to download the ID - of the product from the database so that it will be passed to the URL address:
I managed to do something like this:
http://localhost/seo2/api/admin/domains/notes/{{domainID}}
I would like something like this:
http://localhost/seo2/api/admin/domains/{{domainID}}/notes
My model -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);
}
}
My model 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');
}
}
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 ) . '}';
}
}