출력 Output Class

출력클래스는 하나의 주 함수를 가진 작은 클래스 입니다: 브라우저로 최종 결과물을 보낼 때 사용합니다. 또한 웹페이지의 캐싱(caching) 을 사용하신다면 그 부분도 담당합니다.

Note

이 클래스는 시스템에서 자동으로 초기화 됩니다.

일반적인 상황에서 여러분은 출력클래스의 존재를 알아채지도 못할 것입니다. 출력클래스는 여러분의 간섭이 필요하지 않으며 투명하게 작동합니다. 예를 들어, 뷰 파일을 로드하기 위해 로더(Loader) 클래스를 사용할 때, 로더는 자동으로 그것을 CI 에서 최종적으로 자동 호출 되는 출력클래스로 전달합니다. 그러나, 필요하면 다음 두 함수를 이용하여 출력클래스를 작동에 여러분이 끼어들수 있습니다.

클래스 레퍼런스 Class Reference

class CI_Output
$parse_exec_vars = TRUE;

0.0173 와0.79MB 변수를 파싱할지 결정.

CodeIgniter 는 기본적으로 출력구문에서 위를 파싱할 것입니다. 해제하기 위해, 컨트롤러에서 값을 FALSE 로 변경해주세요.

$this->output->parse_exec_vars = FALSE;
set_output($output)
인수:
  • $output (string) – String to set the output to
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

최종 출력 문자열을 수동으로 설정할 수 있도록 해 줍니다. 사용 예제:

$this->output->set_output($data);

Important

만약 출력을 수동으로 설정한다면, 출력 설정을 하는 함수에서 마지막으로 수행하는 작업이 되어야 합니다. 예를 들어, 컨트롤러의 어떤 함수에서 페이지를 생성한다면, 반드시 맨 마지막에 출력을 설정하셔야 합니다.

set_content_type($mime_type[, $charset = NULL])
인수:
  • $mime_type (string) – MIME Type idenitifer string
  • $charset (string) – Character set
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

JSON 데이터, JPEG, XML 등을 손쉽게 제공하기 위해서 마임타입을 (mime-type)을 설정합니다.

$this->output
        ->set_content_type('application/json')
        ->set_output(json_encode(array('foo' => 'bar')));

$this->output
        ->set_content_type('jpeg') // You could also use ".jpeg" which will have the full stop removed before looking in config/mimes.php
        ->set_output(file_get_contents('files/something.jpg'));

Important

application/config/mimes.php 에 있는 마임타입 외의 것을 설정하면, 작동하지않습니다.

2번째 파라미터에 전달하여, 문서의 문자셋을 설정할 수 있습니다:

$this->output->set_content_type('css', 'utf-8');
get_content_type()
반환값:Content-Type string
반환형:string

현재 사용 중인 Content-Type HTTP 헤더를 반환합니다. 캐릭터셋 값 제외.

$mime = $this->output->get_content_type();

Note

세팅되어있지 앟다면 기본값은 ‘text/html’ 입니다.

get_header($header)
인수:
  • $header (string) – HTTP header name
반환값:

HTTP response header or NULL if not found

반환형:

mixed

요청된 HTTP 헤더 값을 반환합니다. 또는 헤더가 정의되어있지 않으면 NULL 을 반환합니다. Example:

$this->output->set_content_type('text/plain', 'UTF-8');
echo $this->output->get_header('content-type');
// Outputs: text/plain; charset=utf-8

Note

헤더 일므은 대소문자를 구분하지 않습니다.

Note

PHP 내장 함수인 header() 함수를 통해서 보내진 원시 헤더 값도 발견됩니다.

get_output()
반환값:Output string
반환형:string

출력 클래스에서 저장을 위해서 전송되는 어떤 내용이라도 뽑아낼수 있게 해줍니다. 사용 예제:

$string = $this->output->get_output();

이미 출력 클래스로 전송된 데이터만 가져올 수 있다는 것을 명심하세요 . 예를 들어 $this->load->view() 함수 등을 호출하면 데이터가 출력 클래스로 전송된답니다.

append_output($output)
인수:
  • $output (string) – Additional output data to append
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

출력 문자열에 데이터를 추가합니다.

$this->output->append_output($data);
set_header($header[, $replace = TRUE])
인수:
  • $header (string) – HTTP response header
  • $replace (bool) – Whether to replace the old header value, if it is already set
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

서버헤더(server headers)를 설정하는데 사용합니다 예제:

$this->output->set_header('HTTP/1.0 200 OK');
$this->output->set_header('HTTP/1.1 200 OK');
$this->output->set_header('Last-Modified: '.gmdate('D, d M Y H:i:s', $last_update).' GMT');
$this->output->set_header('Cache-Control: no-store, no-cache, must-revalidate');
$this->output->set_header('Cache-Control: post-check=0, pre-check=0');
$this->output->set_header('Pragma: no-cache');
set_status_header([$code = 200[, $text = '']])
인수:
  • $code (int) – HTTP status code
  • $text (string) – Optional message
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

서버상태를 설정하는데 사용합니 예제:

$this->output->set_status_header('401');
// Sets the header as:  Unauthorized

여기 를 보시면 헤더 전체 목록이 있습니다.

Note

이 함수는공통 함수(Common function)set_status_header() 의 Alias 입니다.

enable_profiler([$val = TRUE])
인수:
  • $val (bool) – Whether to enable or disable the Profiler
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

프로파일러(Profiler) 를 활성/비활성 할하는데 사용합니다. 프로파일러는 디버깅이나 프로세스 최적화를위해 벤치마크등의 정보를 페이지 하단에표시 합니다.

프로파일러를 활성화(enable)하려면 아래 코드를 컨트롤러(Controller) 에서 원하는 함수에 추가하시면 됩니다:

$this->output->enable_profiler(TRUE);

활성화되면 페이지의 맨 아래에 리포트가 생성됩니다.

비활성으로 하시려면 아래와 같이 합니다:

$this->output->enable_profiler(FALSE);
set_profiler_sections($sections)
인수:
  • $sections (array) – Profiler sections
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

프로파일러가 활성화 된 경우 특정 색션을 켜거나 끌수 있습니다. 상세한 정보는 프로파일러 (Profiler) 페이지에.

cache($time)
인수:
  • $time (int) – Cache expiration time in minutes
반환값:

CI_Output instance (method chaining)

반환형:

CI_Output

지정된 시간 (분)동안 현재 페이지를 캐시

더 많은 정보를 원하시면, 다음 캐싱 문서 (caching documentation)를 참조하세요.

_display([$output = ''])
인수:
  • $output (string) – Output data override
반환값:

void

반환형:

void

모든 서버 헤더와 함께 브라우저에 확정된 출력 데이터를 전송합니다. 또한 벤치 마크 타이머를 중지합니다.

Note

이 함수는 스크립트 실행의 끝에서 자동으로 호출됩니다, 코드에서 exit()die() 를 사용하여 스크립트를 중지하지 않는한, 수동으로 호출할 필요가 없습니다.

예제:

$response = array('status' => 'OK');

$this->output
        ->set_status_header(200)
        ->set_content_type('application/json', 'utf-8')
        ->set_output(json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES))
        ->_display();
exit;

Note

스크립트 실행을 중단하지 않고 수동으로이 메소드를 호출하면 중복 출력이 됩니다.