2012-05-17 17 views
5

का उपयोग कर सत्यापन के बाद POST डेटा का उपयोग करना मेरे पास एक साइनअप फॉर्म है जहां मैं उपयोगकर्ता इनपुट को मान्य कर रहा हूं। यहाँ मेरी नियंत्रक है:कोडइग्निटर

<?php if (! defined('BASEPATH')) exit('No direct script access allowed'); 

class Register extends CI_Controller { 

    public function index() 
    { 
     $this->load->model('Users_model'); 
     $this->load->helper('form'); 
     $this->load->library('form_validation'); 

     $data['page_title'] = 'Register'; 
     $this->load->view('header', $data); 

     // Set form validation rules 
     $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[16]|xss_clean|callback_username_check'); 
     $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[5]|max_length[64]|valid_email|callback_email_check'); 
     $this->form_validation->set_rules('password', 'Password', 'required'); 
     $this->form_validation->set_error_delimiters('<span class="error">', '</span>'); 

     if ($this->form_validation->run() == FALSE) 
     { 
      $this->load->view('register', $data); 
     } 
     else 
     { 
      // Add the user to the database 
      $this->Users_model->add_user(); 
      $this->load->view('register_success', $data); 
     } 

     $this->load->view('footer', $data); 
    } 

    /* Functions to check username and email */ 
} 

/* End of file register.php */ 
/* Location: ./application/controllers/register.php */ 

समस्या इस लाइन के साथ है: $this->Users_model->add_user();। मैं उपयोगकर्ता को अपने डेटाबेस में उपयोगकर्ता जोड़ने के लिए उपयोगकर्ता नाम, ईमेल और पासवर्ड पास करना चाहता हूं, लेकिन मुझे यकीन नहीं है कि मैं उस विधि में POST डेटा कैसे प्राप्त कर सकता हूं। आम तौर पर मैं $_POST['username'] आदि का उपयोग करता हूं लेकिन कोडइग्निटर ने इनपुट मानों पर कुछ फ़ंक्शन चलाए हैं (trim(), xss_clean आदि)। मैं इन मानों को कैसे प्राप्त कर सकता हूं और उन्हें अपने add_user() विधि में कैसे पास कर सकता हूं?

उत्तर

13

CodeIgniter input class आपको फॉर्म सत्यापन लायब्रेरी द्वारा फ़िल्टर किए जाने के बाद POST डेटा प्राप्त करने की अनुमति देता है। अपने नियंत्रक में आप क्या करेंगे निम्नलिखित:

$username = $this->input->post('username'); 
$email = $this->input->post('email'); 
$password = $this->input->post('password'); 
+0

सोचा करने के लिए सरणी भेज यह होगा लेकिन मुझे यकीन नहीं था कि सोचा था कि मैं पूछूंगा। धन्यवाद। :) –

+0

आपका स्वागत है! क्या आप मेरा जवाब स्वीकार करते हैं या स्वीकार करते हैं? – birderic

+0

एसओ मुझे तुरंत जवाब स्वीकार करने की अनुमति नहीं देता है, स्पष्ट रूप से मैं 3 मिनट में कर सकता हूं। :) –

0

आप सहायक समारोह के रूप में रूप में अच्छी तरह इनपुट वर्ग का उपयोग कर सकते set_value('email')

1

और भी आसान, एक सरणी बना सकते हैं और मॉडल