PHP代码点火器中的共享对象和变量访问范围


Sharing object and variable accessing scope in PHP codeigniter

我不是PHP开发专家,但我已经脱离了JAVA,并受到代码组织技术的困扰。

我有一个控制器类,它扩展了MY_controller调用,其中包含一些受保护的变量,如。

->User_ID
->Pofile_ID

在这里,我有一个payamentprocessing函数存储在一个单独的php类文件"PaymentService.php"中,并且我定义了

payamentprocessing函数定义了它们的类:

 public function processPayment() {
        //load helper and libraries for 
        //validating the input from the form
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        //$post = $this->input->post();
        //retrieve form data and sanitize
        $card_number = $this->sanitize($_POST['card_number']);                
}

所以,我想要的是例如

如果我实例化PaymentService类并调用ProcessPayement方法,比如说在PaymentController中,我如何能够在我的ProcessPayment方法中获得_POST变量包作为全局和$this上下文。

非常感谢!

$CI =& get_instance();
$post_val=$CI->input->post('YOUR_POST_VARIABLE');
//you can get all post values like this
//$post_vals=$CI->input->post();

更新:您的最终功能将类似于此

 public function processPayment() {
    $CI =& get_instance();
    $CI ->load->helper(array('form', 'url'));
    $CI ->load->library('form_validation');       
    $card_number=$this->sanitize($CI->input->post('card_number')); //assuming sanitize is your member function of your current class               
}