라이브러리

[PHP] Yaf_Dispatcher::getRequest - 요청 인스턴스 검색




Yaf_Dispatcher::getRequest

Yaf_Dispatcher::getRequest는 Yaf 프레임워크의 요청 객체를 반환하는 메서드입니다. 이 메서드는 현재 요청에 대한 정보를 제공하며, 요청 객체를 통해 요청의 헤더, 쿠키, 세션, 파라미터 등 다양한 정보를 가져올 수 있습니다.

예제

#hostingforum.kr
php

// index.php

require_once 'Yaf.php';



// Yaf_Application 객체 생성

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



// Yaf_Dispatcher 객체 생성

$dispatcher = $app->getDispatcher();



// 요청 객체 가져오기

$request = $dispatcher->getRequest();



// 요청 객체의 헤더 가져오기

$headers = $request->getHeaders();

print_r($headers);



// 요청 객체의 쿠키 가져오기

$cookies = $request->getCookies();

print_r($cookies);



// 요청 객체의 세션 가져오기

$session = $request->getSession();

print_r($session);



// 요청 객체의 파라미터 가져오기

$parameters = $request->getParams();

print_r($parameters);



application.ini

#hostingforum.kr
ini

[production]

app.name = "Yaf Framework"

app.version = "1.0"



[production : resources]

app.directory = APPLICATION_PATH "/../application"

app.resource = resources



application.php

#hostingforum.kr
php

// application.php

class Application extends Yaf_Application

{

    public function _initConfig()

    {

        // config.ini 로드

        $this->getDispatcher()->setConfig($this->getConfig());

    }

}



index.php에서 Yaf_Dispatcher::getRequest를 호출하여 요청 객체를 가져올 수 있습니다. 요청 객체를 통해 요청의 헤더, 쿠키, 세션, 파라미터 등 다양한 정보를 가져올 수 있습니다.

요청 객체의 헤더 가져오기

#hostingforum.kr
php

$headers = $request->getHeaders();

print_r($headers);



요청 객체의 쿠키 가져오기

#hostingforum.kr
php

$cookies = $request->getCookies();

print_r($cookies);



요청 객체의 세션 가져오기

#hostingforum.kr
php

$session = $request->getSession();

print_r($session);



요청 객체의 파라미터 가져오기

#hostingforum.kr
php

$parameters = $request->getParams();

print_r($parameters);



이러한 예제를 통해 Yaf_Dispatcher::getRequest를 사용하여 요청 객체를 가져올 수 있으며, 요청 객체를 통해 다양한 정보를 가져올 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 10,077건 / 90 페이지

검색

게시물 검색