Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP codeigniter中共享对象和变量访问范围_Php_Codeigniter - Fatal编程技术网

在PHP codeigniter中共享对象和变量访问范围

在PHP codeigniter中共享对象和变量访问范围,php,codeigniter,Php,Codeigniter,我不是PHP开发专家,但我已经离开了JAVA,并饱受代码组织技术之苦 我有一个控制器类,它扩展了我的_控制器调用,这些调用包含一些受保护的变量,如 ->User_ID ->Pofile_ID 在这里,我有一个paymentprocessing函数存储在一个单独的php类文件“PaymentService.php”中,我已经定义了 payamentprocessing函数定义了它们的类似项: public function processPayment() { //

我不是PHP开发专家,但我已经离开了JAVA,并饱受代码组织技术之苦

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

->User_ID
->Pofile_ID
在这里,我有一个
paymentprocessing
函数存储在一个单独的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
类并调用
ProcessPayment
方法,在
PaymentController
中说,我如何才能将
\u POST
变量作为全局和
$this
上下文获取到我的ProcessPayment方法中

非常感谢

$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               
}

$this->load->helper(数组('form','url')
$this->load->library('form_validation')工作?不,不是我想采用那种风格