Yet Another Framework Yaf_Controller_Abstract 클래스

(Yaf >=1.0.0)


소개

Yaf_Controller_Abstract는 Yaf 시스템의 핵심입니다. MVC는 Model-View-Controller의 약자로 디스플레이 로직에서 애플리케이션 로직을 분리하는 것을 목표로 하는 디자인 패턴입니다.

모든 사용자 정의 컨트롤러는 Yaf_Controller_Abstract를 상속합니다.

사용자 정의 컨트롤러에 대해 __construct 함수를 정의할 수 없으므로 Yaf_Controller_AbstractYaf_Controller_Abstract::init()와 같은 마술 메서드를 제공합니다.

사용자 정의 컨트롤러에서 init() 메서드를 정의한 경우 컨트롤러가 인스턴스화되는 동안 호출됩니다.

액션에 인수가 있을 수 있습니다. 요청이 올 때 요청 매개변수에 동일한 이름 변수가 있으면( Yaf_Request_Abstract::getParam() 참조) 라우팅된 후 Yaf는 이를 액션 메서드에 전달합니다( Yaf_Action_Abstract::execute() 참조).

메모: 이러한 인수는 필터링 없이 직접 가져오므로 사용하기 전에 신중하게 처리해야 합니다.


클래스 개요

                  
abstract class Yaf_Controller_Abstract {

  /* Properties */
  public $actions;
  protected $_module;
  protected $_name;
  protected $_request;
  protected $_response;
  protected $_invoke_args;
  protected $_view;

  /* Methods */
  final private __construct()
  protected display(string $tpl, array $parameters = ?): bool
  public forward(string $action, array $paramters = ?): bool
  public getInvokeArg(string $name): void
  public getInvokeArgs(): void
  public getModuleName(): string
  public getName(): string
  public getRequest(): Yaf_Request_Abstract
  public getResponse(): Yaf_Response_Abstract
  public getView(): Yaf_View_Interface
  public getViewpath(): string
  public init(): void
  public initView(array $options = ?): void
  public redirect(string $url): bool
  protected render(string $tpl, array $parameters = ?): string
  public setViewpath(string $view_directory): void
}
                  
                

Properties

actions
이 속성과 Yaf_Action_Abstract를 사용하여 별도의 PHP 스크립트에서 작업 메서드를 정의할 수도 있습니다.

예제 #1 별도의 파일에서 작업 정의

                       
<?php
class IndexController extends Yaf_Controller_Abstract {
    protected $actions = array(
        /** now dummyAction is defined in a separate file */
        "dummy" => "actions/Dummy_action.php",
    );

    /* action method may have arguments */
    public function indexAction($name, $id) {
       /* $name and $id are unsafe raw data */
       assert($name == $this->getRequest()->getParam("name"));
       assert($id   == $this->_request->getParam("id"));
    }
}
?>
                       
                     

예제 #2 Dummy_action.php

                       
<?php
class DummyAction extends Yaf_Action_Abstract {
    /* an action class shall define this method as the entry point */
    public function execute() {
    }
}
?>
                       
                     
_module
module name
_name
controller name
_request
current request object
_response
current response object
_invoke_args
_view
view engine object

목차