정의 위치

  • ./classes/context/Context.class.php

정의 내용

/**
 * Return key's value
 *
 * @param string $key Key
 * @return string Key
 */
function get($key)
{
    is_a($this, 'Context') ? $self = $this : $self = self::getInstance();

    if(!isset($self->context->{$key}))
    {
        return null;
    }
    return $self->context->{$key};
}

 

용도

  • 키에 등록된 값을 반환합니다.
  • 또는 GET, POST 등의 방법으로 클라이언트가 전달한 변수를 포함하고 있습니다.
  • 키에 값을 등록할 때는 Context::set() 메소드를 이용합니다.
  • {$key} 형식의 템플릿 문법은 PHP 코드로 변환될 때 Context::get('key')가 반환하는 값을 출력합니다.
  • 여러 키 값을 한꺼번에 가져오고 싶을 때는 Context::gets() 메소드를 이용합니다.

주요 키

  • logged_info : 로그인 정보, 로그인 된 회원의 정보
    • $logged_info = Context::get('logged_info');
    • $logged_info->is_admin === 'Y' 이면 관리자
    • $logged_info->member_srl : 로그인 한 회원의 회원 번호
  • is_logged : 로그인 여부
    • Context::get('is_logged') : 로그인 상태면 TRUE, 로그인 상태가 아닐 경우 FALSE

파라메터

  • string $key : 변수 이름 문자열입니다. Context::set('key', $var); 로 전달한 변수를 Context::get('key'); 로 불러올 수 있습니다.

예시

  1. ./modules/editor/components/emoticon/emoticon.class.php 내용 중 getEmoticonList() 메소드.
    • 클라이언트가 요청한 이모티콘 세트의 이미지들을 AJAX 통신으로 반환한다. 클라이언트가 요청한 emoticon 변수는 어떤 이모티콘 세트를 반환할 것인지를 결정한다. 클라이언트의 요청은 Context::get('emoticon') 으로 확인한다. 클라이언트는 XML, JSON 등의 형식으로 emoticon 변수를 전달할 수 있다. XE Core는 어떤 형식인지 자동으로 감지해서 Context::get() 메소드로 값을 얻을 수 있도록 해준다.
    • /**
      		 * @brief Returns a list of emoticons file
      		 */
      		function getEmoticonList()
      		{
      		    $emoticon = Context::get('emoticon');
      		    if(!$emoticon || !preg_match("/^([a-z0-9\_]+)$/i",$emoticon)) return new Object(-1,'msg_invalid_request');
      		
      		    $list = $this->getEmoticons($emoticon);
      		
      		    $this->add('emoticons', implode("\n",$list));
      		}
  2. ./modules/editor/components/emoticon/tpl/popup.html 내용 중 $emoticon_list
    • emoticon_list 변수는 ./modules/editor/components/emoticon/emoticon.class.php 의 getPopupContent() 중 Context::set('emoticon_list', $emoticon_list); 에 의해 설정된 값을 반환한다.
    • 예시 코드는 {$key} 보다는 응용된 형태이다.
    • <load target="popup.js" />
      		<load target="popup.css" />
      		<section class="section">
      		    <h1>{$component_info->title} ver. {$component_info->version}</h1>
      		    <div class="x_clearfix">
      		        <div class="x_pull-right">
      		            <select name="list" id="selectEmoticonList">
      		                <!--@foreach($emoticon_list as $key => $val)-->
      		                <option <!--@if($val=='msn')-->selected="select"<!--@end--> value="{$val}">{$val}</option>
      		                <!--@end-->
      		            </select>
      		        </div>
      		    </div>
      		    <div id="emoticons" style="height:1px"></div>
      		</section>