curd operations api
<?php
// header("Access-Control-Allow-Methods: GET, OPTIONS");
// header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding");
// defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct($config = 'rest')
{
parent::__construct($config);
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
die();
}
}
// public function __construct($config = 'rest')
// {
// header('Access-Control-Allow-Origin: *');
// header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
// parent::__construct();
// }
//public function __construct()
// {
// header(‘Access-Control-Allow-Origin: *’);
// header(“Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method”);
// header(“Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE”);
// $method = $_SERVER[‘REQUEST_METHOD’];
// }
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
// $users= $this->db->get('ng_curd')->result();
$jsonResponse = json_encode($this->db->get('ng_curd')->result());
echo $jsonResponse;
}
public function home(){
$json = json_decode(file_get_contents('php://input'), TRUE);
// $json = json_decode($json, true);
$name= $json['name'];
$mobile = $json['mobile'];
$email = $json['email'];
$password = $json['password'];
$dob = $json['dob'];
$this->db->insert('form', array('name'=>$name,
'mobile'=>$mobile,
'email'=>$email,
'password'=>md5($password),
'dob'=>$dob
));// echo 'ffdddsadffad';
// $request= json_decode(file_get_contents('php://input'), TRUE);
// foreach($request as $req){
// // echo $req[2];
// // print_r($req); echo '<br>';
// // echo $this->input->post($req['name']);
// echo $req['name'];
// echo $json['name'];
// echo $data->name; echo "<br/>";
// }
// $username = http.post('name');
// echo $username;
// echo $this->input->post('mobile');
// echo $this->input->post('email');
// echo $username;
// $this->db->insert('demo', array('name'=>'name'));
// echo 'success';
}
public function delete_row($id){
$this->db->where('curd_id', $id)->delete('ng_curd');
}
public function getWeb(){ // showing all the db records in frond end
$jsonResponse = json_encode($this->db->get('form')->result());
echo $jsonResponse;
}
public function edit_row($id){
$res = $this->db->where('user_id', $id)->get('form')->row();
echo json_encode($res);
// echo $id;
}
public function getrow($id){
$res = $this->db->where('curd_id', $id)->get('ng_curd')->row();
echo json_encode($res);
}
public function updaterow(){
$json = json_decode(file_get_contents('php://input'), TRUE);
// $json = json_decode($json, true);
$id= $json['id'];
$name= $json['name'];
$mobile = $json['mobile'];
$email = $json['email'];
$dob = $json['dob'];
$this->db->where('user_id', $id)->update('form', array('name'=>$name, 'mobile'=>$mobile,
'email'=>$email,
'dob'=>$dob));
}
public function createUser(){
$json = json_decode(file_get_contents('php://input'), TRUE);
$fname = $json['firstName'];
$lname = $json['lastName'];
$email = $json['email'];
$data= array('fname'=>$fname,
'lname'=>$lname,
'email'=>$email);
$this->db->insert('ng_curd', $data);
}
public function updateUser(){
$json = json_decode(file_get_contents('php://input'), TRUE);
$id= $json['curd_id'];
$fname = $json['fname'];
$lname = $json['lname'];
$email = $json['email'];
$data= array('fname'=>$fname,
'lname'=>$lname,
'email'=>$email);
$this->db->where('curd_id', $id)->update('ng_curd', $data);
}
}
// header("Access-Control-Allow-Methods: GET, OPTIONS");
// header("Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding");
// defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct($config = 'rest')
{
parent::__construct($config);
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method, Authorization");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if ($method == "OPTIONS") {
die();
}
}
// public function __construct($config = 'rest')
// {
// header('Access-Control-Allow-Origin: *');
// header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
// parent::__construct();
// }
//public function __construct()
// {
// header(‘Access-Control-Allow-Origin: *’);
// header(“Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method”);
// header(“Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE”);
// $method = $_SERVER[‘REQUEST_METHOD’];
// }
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
// $users= $this->db->get('ng_curd')->result();
$jsonResponse = json_encode($this->db->get('ng_curd')->result());
echo $jsonResponse;
}
public function home(){
$json = json_decode(file_get_contents('php://input'), TRUE);
// $json = json_decode($json, true);
$name= $json['name'];
$mobile = $json['mobile'];
$email = $json['email'];
$password = $json['password'];
$dob = $json['dob'];
$this->db->insert('form', array('name'=>$name,
'mobile'=>$mobile,
'email'=>$email,
'password'=>md5($password),
'dob'=>$dob
));// echo 'ffdddsadffad';
// $request= json_decode(file_get_contents('php://input'), TRUE);
// foreach($request as $req){
// // echo $req[2];
// // print_r($req); echo '<br>';
// // echo $this->input->post($req['name']);
// echo $req['name'];
// echo $json['name'];
// echo $data->name; echo "<br/>";
// }
// $username = http.post('name');
// echo $username;
// echo $this->input->post('mobile');
// echo $this->input->post('email');
// echo $username;
// $this->db->insert('demo', array('name'=>'name'));
// echo 'success';
}
public function delete_row($id){
$this->db->where('curd_id', $id)->delete('ng_curd');
}
public function getWeb(){ // showing all the db records in frond end
$jsonResponse = json_encode($this->db->get('form')->result());
echo $jsonResponse;
}
public function edit_row($id){
$res = $this->db->where('user_id', $id)->get('form')->row();
echo json_encode($res);
// echo $id;
}
public function getrow($id){
$res = $this->db->where('curd_id', $id)->get('ng_curd')->row();
echo json_encode($res);
}
public function updaterow(){
$json = json_decode(file_get_contents('php://input'), TRUE);
// $json = json_decode($json, true);
$id= $json['id'];
$name= $json['name'];
$mobile = $json['mobile'];
$email = $json['email'];
$dob = $json['dob'];
$this->db->where('user_id', $id)->update('form', array('name'=>$name, 'mobile'=>$mobile,
'email'=>$email,
'dob'=>$dob));
}
public function createUser(){
$json = json_decode(file_get_contents('php://input'), TRUE);
$fname = $json['firstName'];
$lname = $json['lastName'];
$email = $json['email'];
$data= array('fname'=>$fname,
'lname'=>$lname,
'email'=>$email);
$this->db->insert('ng_curd', $data);
}
public function updateUser(){
$json = json_decode(file_get_contents('php://input'), TRUE);
$id= $json['curd_id'];
$fname = $json['fname'];
$lname = $json['lname'];
$email = $json['email'];
$data= array('fname'=>$fname,
'lname'=>$lname,
'email'=>$email);
$this->db->where('curd_id', $id)->update('ng_curd', $data);
}
}
Comments
Post a Comment