라이브러리
[PHP] Yaf_Dispatcher::setDefaultAction - 기본 작업 이름 변경
Yaf_Dispatcher::setDefaultAction
Yaf_Dispatcher::setDefaultAction은 Yaf 프레임워크의 Dispatcher 클래스에 속하는 메소드입니다. 이 메소드는 Dispatcher의 기본 동작을 설정하는 역할을 합니다.
# 기본 동작이란?
Dispatcher는 요청을 처리하는 과정에서, URL을 분석하여 Controller, Action을 결정하는 역할을 합니다. 기본 동작은 Dispatcher가 요청을 처리하는 방식입니다. 예를 들어, URL이 `/user/index` 인 경우, Dispatcher는 `User` Controller의 `index` Action을 호출합니다.
# setDefaultAction 메소드
setDefaultAction 메소드는 Dispatcher의 기본 동작을 설정하는 메소드입니다. 이 메소드는 `action` 이름을 인수로 받습니다. 예를 들어, `setDefaultAction('index')` 라면, Dispatcher는 기본적으로 `index` Action을 호출합니다.
# 예제
#hostingforum.kr
php
// yaf.php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->setDefaultAction('index'); // 기본 동작을 index Action으로 설정
// index.php
$dispatcher = Yaf_Dispatcher::getInstance();
$controller = $dispatcher->dispatch(); // 기본 동작에 따라 Controller와 Action을 호출
# 예제 설명
위 예제에서, `yaf.php` 파일에서 `setDefaultAction` 메소드를 호출하여 기본 동작을 `index` Action으로 설정합니다. `index.php` 파일에서, `dispatch` 메소드를 호출하여 Dispatcher가 기본 동작에 따라 Controller와 Action을 호출합니다.
# 실제 예제
#hostingforum.kr
php
// yaf.php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->setDefaultAction('index');
// index.php
$dispatcher = Yaf_Dispatcher::getInstance();
$controller = $dispatcher->dispatch('/user'); // 기본 동작에 따라 User Controller의 index Action을 호출
# 실제 예제 설명
위 예제에서, `yaf.php` 파일에서 `setDefaultAction` 메소드를 호출하여 기본 동작을 `index` Action으로 설정합니다. `index.php` 파일에서, `dispatch` 메소드를 호출하여 Dispatcher가 기본 동작에 따라 User Controller의 `index` Action을 호출합니다.
# 참고
setDefaultAction 메소드는 Dispatcher의 기본 동작을 설정하는 역할을 합니다. 이 메소드는 Controller와 Action을 결정하는 데 사용됩니다. Dispatcher의 기본 동작은 URL 분석에 따라 결정됩니다. 예를 들어, URL이 `/user/index` 인 경우, Dispatcher는 `User` Controller의 `index` Action을 호출합니다. 기본 동작을 설정하는 메소드는 `setDefaultAction` 메소드입니다.
댓글목록
등록된 댓글이 없습니다.