라이브러리
[PHP] Yaf_Dispatcher::registerPlugin - 플러그인 등록
Yaf_Dispatcher::registerPlugin
Yaf_Dispatcher::registerPlugin은 Yaf 프레임워크의 Dispatcher 클래스에서 사용되는 메소드입니다. 이 메소드는 Dispatcher에 플러그인을 등록하는 역할을 합니다. 플러그인은 Dispatcher의 동작을 확장하거나 변경하는 데 사용됩니다.
# 플러그인의 종류
Yaf 프레임워크에서 사용할 수 있는 플러그인의 종류는 다음과 같습니다.
* Yaf_Route_Interface: 라우팅을 위한 인터페이스
* Yaf_Controller_Abstract: 컨트롤러를 위한 추상 클래스
* Yaf_Action_Abstract: 액션을 위한 추상 클래스
* Yaf_View_Interface: 뷰를 위한 인터페이스
# 플러그인 등록
플러그인을 등록하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->registerPlugin(new Yaf_Route_Rewrite());
# 예제
아래 예제에서는 Yaf_Route_Rewrite 플러그인을 등록하고, 라우팅을 사용하여 URL을 처리하는 방법을 보여줍니다.
#hostingforum.kr
php
// application.ini
[production]
app.script_path = APPLICATION_PATH . "/scripts"
app.view_script_path = APPLICATION_PATH . "/views"
app.dispatcher.defaultModule = "index"
app.dispatcher.defaultController = "index"
app.dispatcher.defaultAction = "index"
app.dispatcher.catchException = true
[production : routing]
^index/$ = index, index
^index/(.*)$ = index, index/$1
#hostingforum.kr
php
// Bootstrap.php
class Bootstrap extends Yaf_Bootstrap_Abstract
{
public function _initRoute(Yaf_Dispatcher $dispatcher)
{
$dispatcher->registerPlugin(new Yaf_Route_Rewrite());
}
}
#hostingforum.kr
php
// indexController.php
class IndexController extends Yaf_Controller_Abstract
{
public function indexAction()
{
echo "Index Controller";
}
public function testAction()
{
echo "Test Controller";
}
}
#hostingforum.kr
php
// index/index.phtml
<?php echo $this->name; ?>
이 예제에서는 Yaf_Route_Rewrite 플러그인을 등록하고, 라우팅을 사용하여 URL을 처리합니다. URL은 index/index로 접근할 수 있습니다.
# 플러그인 사용
플러그인을 사용하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->getPlugin('Yaf_Route_Rewrite')->init();
# 플러그인 초기화
플러그인을 초기화하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->getPlugin('Yaf_Route_Rewrite')->init();
# 플러그인 종료
플러그인을 종료하는 방법은 다음과 같습니다.
#hostingforum.kr
php
$dispatcher = Yaf_Dispatcher::getInstance();
$dispatcher->getPlugin('Yaf_Route_Rewrite')->shutdown();
결론
Yaf_Dispatcher::registerPlugin은 Yaf 프레임워크의 Dispatcher 클래스에서 사용되는 메소드입니다. 이 메소드는 Dispatcher에 플러그인을 등록하는 역할을 합니다. 플러그인은 Dispatcher의 동작을 확장하거나 변경하는 데 사용됩니다. 이 문서에서는 Yaf_Route_Rewrite 플러그인을 등록하고, 라우팅을 사용하여 URL을 처리하는 방법을 보여주었습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.