2016-05-12 46 views
0

我不知道如何獲取值,請幫我排序這個問題。如果有人已經擁有該代碼,請告訴我,然後請分享。我也好奇,如何與捲曲帶一個RESTful API加載火花全過程如何使用CodeIgniter在RESTful API中發送帖子值?

<?php class LoginController extends CI_Controller { 

    public function index() 
    { 
     $this->load->view('admin/header'); 
     $this->load->view('admin/index'); 
     $this->load->view('admin/footer'); 
    } 

    public function loginCon(){ 

$this->load->Library('rest'); 

     $this->form_validation->set_rules('email', 'E-mail', 'required|trim'); 
     $this->form_validation->set_rules('password', 'Password', 'required'); 
     $this->form_validation->set_error_delimiters("<p class='text-danger'>", "</p>"); 

     if ($this->form_validation->run()==false) 
     { 
      $email = $this->input->post('email'); 
      $password = $this->input->post('password'); 
      $this->session->set_flashdata('login_failed', 'Invalid User Name Password'); 

     }else{ 

      $config = array('server' => "http://api.amid.tech/hsApiV2/api/demo.php/", 

       'http_user' => 'admin', 
       'http_pass' => 'xxxxx', 
       'http_auth' => 'basic', 
      ); 
      $this->rest->initialize($config); 
      $method = 'post'; 
      $param = array(
       'UserEmail' => $this->input->post('email'), // works fine here 
       'UserPass' => $this->input->post('password'), 
       'UserRoleId'=>1 
      ); 
      $uri = 'adminlogin'; 
      $this->rest->format('application/json'); 
      $result = $this->rest->{$method}($uri, $param); 
      echo $result; 
      $this->load->view('admin/admin_header'); 
      $this->load->view('admin/sidebar'); 
      $this->load->view("admin/dashboard"); 
      $this->load->view('admin/dashboard.php'); 

     } 


    } 
    public function registerd() 
    { 
     $this->load->view('admin/header'); 
     $this->load->view('admin/registration'); 
     $this->load->view('admin/footer'); 

    } 

} ?> 
+0

你是什麼在代碼中查看? – Manmohan

+0

負載火花捲曲? – epynic

回答

1

要獲得原料投入試

// get the raw POST data 
$rawData = file_get_contents("php://input"); 

爲了驗證嘗試

$this->form_validation->set_rules($rawData['email'], 'E-mail', 'required|trim');