외부 Controller Fetch 외부 Controller를 Fetch하여 종속 시키는 방법을 안내합니다.
부모 Controller에서 외부 Controller Fetch
zigger는 외부 Controller를 웹페이지에 삽입하기 위해 Fetch 기능을 제공합니다.
Controller
/app/test.php
위 예시 코드의 16~21 line과 같이 Controller에 메소드를 정의 후 Fetch 객체를 생성합니다.
생성된 객체에서 set() 을 통해 외부 문서를 Controller에 Fetch 시켜 View에서 출력할 수 있도록 준비 합니다.
<?php
class Testpage extends \Controller\Make_Controller {
public function init()
{
$this->layout()->head();
$this->layout()->view(PH_THEME_PATH.'/html/test.tpl.php');
$this->layout()->foot();
}
public function make()
{
...
}
public function fetch()
{
$fetch = new \Controller\Make_View_Fetch();
$fetch->set('doc', PH_PATH.'/incfile.php');
$fetch->run();
}
}
Fetch할 자식 Controller 작성
부모 Controller에 Fetch되어 종속될 Controller는 아래와 같이 작성합니다.
Controller
/app/incfile.php
위와 같이 부모 Controller Fetch의 set() 에서 설정한 doc 의 파일명과 동일한 이름으로 새로운 Class를 작성합니다.
<?php
class Incfile extends \Controller\Make_Controller {
public function init()
{
$this->layout()->head();
$this->layout()->view(PH_THEME_PATH.'/html/incfile.tpl.php');
$this->layout()->foot();
}
public function make()
{
...
}
}
만약, doc 에서 설정한 파일명과 다른 Class Name으로 Controller를 작성하려는 경우 아래와 같이 부모 Controller에서 className 옵션을 설정합니다.
Controller
/app/test.php
혹은,
<?php
class Testpage extends \Controller\Make_Controller {
public function init()
{
$this->layout()->head();
$this->layout()->view(PH_THEME_PATH.'/html/test.tpl.php');
$this->layout()->foot();
}
public function make()
{
...
}
public function fetch()
{
$fetch = new \Controller\Make_View_Fetch();
$fetch->set('doc', PH_PATH.'/incfile.php');
$fetch->set('className', 'setClassName');
$fetch->run();
}
}
Controller
/app/test.php
<?php
class Testpage extends \Controller\Make_Controller {
public function init()
{
$this->layout()->head();
$this->layout()->view(PH_THEME_PATH.'/html/test.tpl.php');
$this->layout()->foot();
}
public function make()
{
...
}
public function fetch()
{
$fetch = new \Controller\Make_View_Fetch();
$fetch->set('doc', PH_PATH.'/incfile.php');
$fetch->set('className', 'Module\Board\setClassName');
$fetch->run();
}
}
View에서 Fetch된 Controller 출력
부모 Controller에서 Fetch하여 자신 Controller를 결합한 뒤 아래 예시와 같이 부모 Controller View에서 출력합니다.
View
/html/zigger-default/test.tpl.php
<?php $this->fetch(); ?>
연관 가이드 바로가기
Manager 사용하기
파일 및 디렉토리 구성 자세히 보기
