home.php
이름 podetails
이 지정된 함수가있는 컨트롤러가 하나 있습니다. 다른 컨트롤러에서이 함수를 호출하고 싶습니다 user.php
.
그렇게 할 수 있습니까? HMVC
CI에서 읽었 지만 hmvc를 사용하지 않고 할 수 있는지 알고 싶습니다.
컨트롤러를 확장하려면이 튜토리얼을 따르 거나 아래 코드를 참조하십시오.
개인 / 공개 / 보호의 차이점
폴더에있는 파일 수 있도록 /application/core/
이름을MY_Controller.php
해당 파일 내에 다음과 같은 코드가 있습니다.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Controller extends CI_Controller {
protected $data = Array(); //protected variables goes here its declaration
function __construct() {
parent::__construct();
$this->output->enable_profiler(FALSE); // I keep this here so I dont have to manualy edit each controller to see profiler or not
$this->load->model('some_model'); //this can be also done in autoload...
//load helpers and everything here like form_helper etc
}
protected function protectedOne() {
}
public function publicOne() {
}
private function _privateOne() {
}
protected function render($view_file) {
$this->load->view('header_view');
if ($this->_is_admin()) $this->load->view('admin_menu_view');
$this->load->view($view_file . '_view', $this->data); //note all my view files are named <name>_view.php
$this->load->view('footer_view');
}
private function _isAdmin() {
return TRUE;
}
}
이제 기존 컨트롤러에서 첫 번째 또는 두 번째 줄을 편집하십시오.
class <controller_name> extends MY_Controller {
그리고 당신은 끝났습니다
또한보기에서 사용되는 모든 변수는이 변수에 있습니다. (array) $this->data
확장 된 일부 컨트롤러의 예 MY_Controller
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class About extends MY_Controller {
public function __construct() {
parent::__construct();
}
public function index() {
$this->data['today'] = date('Y-m-d'); //in view it will be $today;
$this->render('page/about_us'); //calling common function declared in MY_Controller
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다