라이브러리

[PHP] Yaf_Controller_Abstract::getName - 자기 이름 가져오기




Yaf_Controller_Abstract::getName


Yaf_Controller_Abstract::getName은 Yaf 프레임워크의 Controller 클래스에서 사용할 수 있는 메서드입니다. 이 메서드는 현재 Controller의 이름을 반환합니다.

사용 방법


Yaf_Controller_Abstract::getName을 사용하는 방법은 다음과 같습니다.

#hostingforum.kr
php

// Controller.php

class Controller extends Yaf_Controller_Abstract {

    public function indexAction() {

        $controllerName = $this->getName();

        echo "Controller Name : $controllerName";

    }

}



예제


Yaf 프레임워크를 사용하여 Controller를 만들고, getName 메서드를 사용하는 예제입니다.

#hostingforum.kr
php

// index.php

// Yaf_Application 객체를 생성합니다.

$app = new Yaf_Application('application.ini');



// Yaf_Application 객체를 실행합니다.

$app->run();



#hostingforum.kr
php

// application.ini

[application]

appdir = APPLICATION_PATH "/application"

module.dir = APPLICATION_PATH "/modules"

resource.dir = APPLICATION_PATH "/resources"



[production]

yaf.environ = production

yaf.use_namespace = Yaf_Namespace



[development]

yaf.environ = development

yaf.use_namespace = Yaf_Namespace



[testing]

yaf.environ = testing

yaf.use_namespace = Yaf_Namespace



#hostingforum.kr
php

// application/controllers/Controller.php

class Controller extends Yaf_Controller_Abstract {

    public function indexAction() {

        $controllerName = $this->getName();

        echo "Controller Name : $controllerName";

    }

}



#hostingforum.kr
php

// application/controllers/IndexController.php

class IndexController extends Controller {

    public function indexAction() {

        echo "Index Controller";

    }

}



이 예제에서, `Controller` 클래스는 `Yaf_Controller_Abstract` 클래스를 상속하고, `getName` 메서드를 사용하여 현재 Controller의 이름을 반환합니다. `IndexController` 클래스는 `Controller` 클래스를 상속하고, `indexAction` 메서드를 정의하여 Index Controller의 이름을 출력합니다.

결과


이 예제를 실행하면, 다음과 같은 결과가 출력됩니다.

#hostingforum.kr


Controller Name : IndexController



이 예제는 Yaf 프레임워크의 Controller 클래스에서 사용할 수 있는 `getName` 메서드를 사용하는 방법을 보여줍니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 8,985건 / 24 페이지

검색

게시물 검색