我想知道我怎麼能叫在Appointments
類可我index
功能,結構是這樣的:如何從另一個類調用一個類的函數?
class Appointments extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
if ($this->session->userdata('language'))
{
$this->config->set_item('language', $this->session->userdata('language'));
$this->lang->load('translations', $this->session->userdata('language'));
}
else
{
$this->lang->load('translations', $this->config->item('language'));
}
}
/**
* @param string $appointment_hash
*/
public function index($appointment_hash = '')
{...
從名爲Backend_api
另一個類。通常用於調用一個函數,我加載模型,但在這種情況下,我沒有模型,但只有一個類。對不起,如果問題是愚蠢的,但我在CodeIgniter
新,我沒有發現任何可以幫助我。
現在的問題是我已經有了一個擴展,現在我怎麼可以擴展多個類? – Dillinger
你不能(http://php.net/manual/en/keyword.extends.php) 爲了解決這個問題,你可以在上面建議的Backend_api中創建一個Appointments類的實例。 更好的方法是使用Dependancy Injection:http://php-di.org/doc/understanding-di.html/code.tutsplus.com/tutorials/dependency-injection-in-php--net -28146 –