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