<?php class Myapp extends CI_Controller { function index() { $this->load->helper(array('form', 'url')); $this->load->view("myapp"); } } ?>
<html> <head> <title>My Form</title> </head> <body> <?php echo validation_errors(); ?> <?php echo form_open('api/wsdate/day'); ?> <h5>Username</h5> <input type="text" name="username" value="" size="50" /> <h5>Date</h5> <input type="text" name="date" value="" size="50" /> <div><input type="submit" value="Submit" /></div> </form> </body> </html>
<?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/ * url sample : http://127.0.0.1/REST/ci/index.php/api/wsdate/day/jj-mm-yyyy/13-12-2014 */ // This can be removed if you use __autoload() in config.php OR use Modular Extensions require APPPATH.'/libraries/REST_Controller.php'; class Wsdate extends REST_Controller { function __construct() { // Construct our parent class parent::__construct(); // Configure limits on our controller methods. Ensure // you have created the 'limits' table and enabled 'limits' // within application/config/rest.php $this->methods['today_get']['limit'] = 500; //500 requests per hour per user/key } function QuelJour($parm) { $aJour[1]="Lundi"; $aJour[2]="Mardi"; $aJour[3]="Mercredi"; $aJour[4]="Jeudi"; $aJour[5]="Vendredi"; $aJour[6]="Samedi"; $aJour[7]="Dimanche"; return $aJour[date("w",strtotime($parm))]; } function day_get() { if(!$this->get('jj-mm-yyyy')) { $this->response(NULL, 400); } $jour=$this->QuelJour($this->get('jour')); if($jour) { $this->response($jour, 200); // 200 being the HTTP response code } else { $this->response(array('error' => 'Jour could not be found'), 404); } } function day_post() { //$this->some_model->updateDate( $this->post('date') ); $message = array('username' => $this->post('username'), 'date' => $this->post('date'), 'res' => $this->QuelJour($this->post('date')), 'message' => 'ADDED IN DATABASE!'); $this->response($message, 200); // 200 being the HTTP response code } }