在 PHP codeigniter 中共享对象和变量访问范围
Sharing object and variable accessing scope in PHP codeigniter
我不是专家 PHP 开发人员,但我已经从 JAVA 转移过来并且受代码组织技术的困扰。
我有一个控制器 class,它扩展了 MY_Controller 具有一些受保护变量的调用。
->User_ID
->Pofile_ID
事情是这样的,我有一个 payamentprocessing
函数存储在一个单独的 php class 文件 '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']);
}
所以,我想要的是 forexample
如果我实例化 PaymentService
Class 并调用 ProcessPayement
方法在 PaymentController
中说我如何才能将 _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
}
我不是专家 PHP 开发人员,但我已经从 JAVA 转移过来并且受代码组织技术的困扰。
我有一个控制器 class,它扩展了 MY_Controller 具有一些受保护变量的调用。
->User_ID
->Pofile_ID
事情是这样的,我有一个 payamentprocessing
函数存储在一个单独的 php class 文件 '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']);
}
所以,我想要的是 forexample
如果我实例化 PaymentService
Class 并调用 ProcessPayement
方法在 PaymentController
中说我如何才能将 _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
}