API

route==$route['webapi/app/(:any)/?(:any)/?(:any)/?(:any)'] = 'api/index';




contrloer=<?php

/**

* create all api details.....

**


*  www.domain.com/webapi/app/top-header

**



*

*/ 


error_reporting(0);


header("Access-Control-Allow-Origin: *");

header("Access-Control-Allow-Headers: *");

class Api extends MY_Controller{

var $status="error";

var $msg="No found data.";

var $data="No found data.";

public function index(){

$type = $this->uri->segment(3);

witch($type){

case 'invoices':

$this->data=$this->get_invoices();

break;

case 'get_invoices_by_id':

$this->data=$this->get_invoices_by_id();

break;

case 'register':

$this->data=$this->register();

break;

}

$set['status']=$this->status;

$set['msg']=$this->msg;

$set['data']=$this->data;

echo json_encode($set,JSON_ERROR_CTRL_CHAR);

}

/*

public function register(){

$id=$this->input->post('id');

   if(empty($id)){

 $this->msg='can not empty id';

return 'No found data.';  

   }

   $this->status='1';

$this->msg='fetch data success';

return $id;

}

public function get_invoices_by_id(){

//$id=$this->input->get('id');

   $id=$this->input->post('id');

   if(empty($id)){

  $this->msg='can not empty id';

return 'No found data.';  

   } 

   $result =$this->get_invoice_data_by_id($id);

    if(empty($result)){

$this->msg='No found data.';

return 'No found data.';  

   }

   $this->status='1';

$this->msg='fetch data success';

return $result;

}

public function get_invoices(){

  $result =$this->get_invoice_data();

    if(empty($result)){

$this->msg='No found data.';

return 'No found data.';  

   }

   $this->status='1';

$this->msg='fetch data success';

return $result;

}

public function get_invoice_data(){

$result=$this->db->get('invoices')->result();

return $result;

}

public function get_invoice_data_by_id($id){

$this->db->where('id',$id);  

$query=$this->db->get('invoices');

$result =$query->row();

return $result;

}






?>

Comments

Popular posts from this blog

condition in table data for html

my notepad code notes

React.js Notes