You've already forked ci_restful
first commit
This commit is contained in:
74
application/controllers/api/barang.php
Normal file
74
application/controllers/api/barang.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
/**
|
||||
* Example
|
||||
*
|
||||
* This is an example of a few basic user interaction methods you could use
|
||||
* all done with a hardcoded array.
|
||||
*
|
||||
* @package CodeIgniter
|
||||
* @subpackage Rest Server
|
||||
* @category Controller
|
||||
* @author Phil Sturgeon
|
||||
* @link http://philsturgeon.co.uk/code/
|
||||
*/
|
||||
|
||||
// This can be removed if you use __autoload() in config.php OR use Modular Extensions
|
||||
require APPPATH.'/libraries/REST_Controller.php';
|
||||
class Barang extends REST_Controller
|
||||
{
|
||||
|
||||
function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model(array('barang_model'));
|
||||
}
|
||||
function a_barang_get() {
|
||||
if(!$this->get('id')) { $this->response(NULL, 400);}
|
||||
else {
|
||||
$query = $this->barang_model->get_barang_by($this->get('id'));
|
||||
if($query) { $this->response($query, 200);}
|
||||
else { $this->response(array('error' => 'User could not be found'), 404); }
|
||||
}
|
||||
}
|
||||
|
||||
function all_barang_get() {
|
||||
$query = $this->barang_model->get_barang_all();
|
||||
if($query) { $this->response($query, 200);}
|
||||
else { $this->response(array('error' => 'User could not be found'), 404); }
|
||||
}
|
||||
function add_barang_post() {
|
||||
$data = array( 'id' => '',
|
||||
'nama' => $this->post('nama_barang'),
|
||||
'harga' => $this->post('harga'));
|
||||
|
||||
$quer = $this->barang_model->simpan_barang($data);
|
||||
|
||||
if($quer) {
|
||||
$this->response(array( 'succes' => 'yes'), 200);
|
||||
}
|
||||
else {
|
||||
$this->response($quer, 404);
|
||||
}
|
||||
}
|
||||
function update_barang_post(){
|
||||
$data = array( 'id' => '',
|
||||
'nama'=> $this->post->('nama_barang'),
|
||||
'harga'=> $this->post('harga'));
|
||||
}
|
||||
/*
|
||||
function update_barang_post() {
|
||||
$data = array( 'nama' => $this->post('nama'),
|
||||
'harga' => $this->post('harga'))
|
||||
$id = $this->get('id');
|
||||
$query = $this->barang_model->update_barang($data, $id);
|
||||
$this->response($query, 200);
|
||||
}
|
||||
|
||||
function del_barang_delete(){
|
||||
$id = $this->get('id');
|
||||
$query = $this->mbarang->del_barang($id); echo "";
|
||||
$this->response($query, 200);
|
||||
}
|
||||
*/
|
||||
}
|
Reference in New Issue
Block a user