라이브러리
[PHP] Yaf_Controller_Abstract::display - 디스플레이 목적
Yaf_Controller_Abstract::display
Yaf_Controller_Abstract::display는 PHP의 Yaf 프레임워크에서 사용되는 메서드입니다. 이 메서드는 컨트롤러에서 뷰를 렌더링하는 데 사용됩니다.
# 사용법
Yaf_Controller_Abstract::display는 다음과 같은 형식으로 사용됩니다.
#hostingforum.kr
php
public function display($tpl = null)
* `$tpl` : 뷰의 템플릿 이름을 지정합니다. 기본값은 `null`입니다.
# 예제
다음 예제는 Yaf 프레임워크에서 사용하는 간단한 뷰를 렌더링하는 예제입니다.
#hostingforum.kr
php
// index.php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
// 뷰를 렌더링합니다.
$this->display('index');
}
}
#hostingforum.kr
php
// application/views/index/index.phtml
인덱스 페이지
인덱스 페이지입니다.
위 예제에서 `IndexController` 클래스의 `indexAction` 메서드에서 `display` 메서드를 호출하여 `index.phtml` 뷰를 렌더링합니다.
# 뷰의 템플릿 이름 지정
뷰의 템플릿 이름은 다음과 같이 지정할 수 있습니다.
#hostingforum.kr
php
// index.php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
// 뷰의 템플릿 이름을 지정합니다.
$this->display('index.phtml');
}
}
# 뷰의 템플릿 이름 지정 (변수 사용)
뷰의 템플릿 이름을 변수를 사용하여 지정할 수도 있습니다.
#hostingforum.kr
php
// index.php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
// 뷰의 템플릿 이름을 변수를 사용하여 지정합니다.
$tpl = 'index';
$this->display($tpl . '.phtml');
}
}
# 뷰의 템플릿 이름 지정 (함수 사용)
뷰의 템플릿 이름을 함수를 사용하여 지정할 수도 있습니다.
#hostingforum.kr
php
// index.php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
// 뷰의 템플릿 이름을 함수를 사용하여 지정합니다.
$tpl = getTplName();
$this->display($tpl . '.phtml');
}
private function getTplName()
{
return 'index';
}
}
결론
Yaf_Controller_Abstract::display 메서드는 컨트롤러에서 뷰를 렌더링하는 데 사용됩니다. 뷰의 템플릿 이름을 지정할 때 `$tpl` 변수를 사용하거나 함수를 사용할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.