【发布时间】:2017-10-06 09:38:52
【问题描述】:
我有两个控制器和一个模型,如下所示,我想在侧面模型中调用第二个控制器方法。但我不知道怎么称呼它。
1) 控制器1
class controller1 extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('job');
}
public function getjob() {
$this->job->check_payment();
}
}
2) Paypal.php(控制器)
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Paypal extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->model('job');
// Load helpers
$this->load->helper('url');
// Load PayPal library
$this->config->load('paypal');
$config = array(
'Sandbox' => $this->config->item('Sandbox'),
'APIUsername' => $this->config->item('APIUsername'),
'APIPassword' => $this->config->item('APIPassword'),
'APISignature' => $this->config->item('APISignature'),
'APISubject' => '',
'APIVersion' => $this->config->item('APIVersion')
);
// Show Errors
if ($config['Sandbox']) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
$this->load->library('Paypal_pro', $config);
}
function sendPayemnt() {
echo "Hello...";
}
}
2) Job.php(模型)
class Job extends CI_Model {
function check_payment() {
// I want to call method of Paypal controller here...
}
}
我希望有人帮助我解决它。 谢谢,
【问题讨论】:
-
为什么要脱离 Codeigniter 的结构?
-
编写一个辅助函数而不是控制器并从模型中调用它。这是 Codeigniter 的正确结构。
-
我知道这不是有效的编码结构,但这是满足我要求的唯一方法。
标签: php codeigniter