我有兩個控制器和一個模型如下,我想調用旁邊模型中的第二個控制器方法。但我不知道如何調用它。Codeigniter呼叫控制器方法從模型
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的正確結構。 –
我知道這是無效的編碼結構,但這只是達到我的要求的方法。 – Hardik