HTML 헬퍼¶
HTML 헬퍼 파일에는 HTML 작업을 도와주는 함수가 포함되어 있습니다.
헬퍼 로드¶
이 헬퍼는 다음 코드를 사용하여 로드합니다:
$this->load->helper('html');
사용 가능한 함수¶
사용 가능한 함수는 다음과 같습니다:
- heading([$data = ''[, $h = '1'[, $attributes = '']]])¶
- 매개변수:
$data (
string) – 내용$h (
string) – 제목 수준$attributes (
mixed) – HTML 속성
- 반환:
HTML 제목 태그
- 반환 형식:
string
HTML 제목 태그를 생성할 수 있습니다. 첫 번째 매개변수에 데이터, 두 번째 매개변수에 제목 크기를 전달합니다. 예시:
echo heading('Welcome!', 3);
위 코드는 다음을 생성합니다: <h3>Welcome!</h3>
또한 HTML 클래스, id 또는 인라인 스타일과 같은 속성을 제목 태그에 추가하려면 세 번째 매개변수에 문자열 또는 배열을 전달합니다:
echo heading('Welcome!', 3, 'class="pink"'); echo heading('How are you?', 4, array('id' => 'question', 'class' => 'green'));
위 코드는 다음을 생성합니다:
<h3 class="pink">Welcome!<h3> <h4 id="question" class="green">How are you?</h4>
- img([$src = ''[, $index_page = FALSE[, $attributes = '']]])¶
- 매개변수:
$src (
string) – 이미지 소스 데이터$index_page (
bool) – $src를 라우팅된 URI 문자열로 처리할지 여부$attributes (
array) – HTML 속성
- 반환:
HTML 이미지 태그
- 반환 형식:
string
HTML <img /> 태그를 생성할 수 있습니다. 첫 번째 매개변수에 이미지 소스를 전달합니다. 예시:
echo img('images/picture.jpg'); // gives <img src="http://site.com/images/picture.jpg" />
선택적인 두 번째 매개변수는 TRUE/FALSE 값으로, src에
$config['index_page']로 지정된 페이지를 주소에 추가할지 여부를 지정합니다. 미디어 컨트롤러를 사용하는 경우 이 옵션을 사용합니다:echo img('images/picture.jpg', TRUE); // gives <img src="http://site.com/index.php/images/picture.jpg" alt="" />
또한 연관 배열을
img()함수에 전달하여 모든 속성과 값을 완전히 제어할 수 있습니다. alt 속성이 제공되지 않으면 CodeIgniter가 빈 문자열을 생성합니다.예시:
$image_properties = array( 'src' => 'images/picture.jpg', 'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time', 'class' => 'post_images', 'width' => '200', 'height'=> '200', 'title' => 'That was quite a night', 'rel' => 'lightbox' ); img($image_properties); // <img src="http://site.com/index.php/images/picture.jpg" alt="Me, demonstrating how to eat 4 slices of pizza at one time" class="post_images" width="200" height="200" title="That was quite a night" rel="lightbox" />
- link_tag([$href = ''[, $rel = 'stylesheet'[, $type = 'text/css'[, $title = ''[, $media = ''[, $index_page = FALSE]]]]]])¶
- 매개변수:
$href (
string) – 링크 대상$rel (
string) – 관계 유형$type (
string) – 관련 문서의 유형$title (
string) – 링크 제목$media (
string) – 미디어 유형$index_page (
bool) – $src를 라우팅된 URI 문자열로 처리할지 여부
- 반환:
HTML 링크 태그
- 반환 형식:
string
HTML <link /> 태그를 생성할 수 있습니다. 스타일시트 링크 및 기타 링크에 유용합니다. 매개변수는 href이며 선택적으로 rel, type, title, media, index_page를 사용합니다.
index_page는 href에
$config['index_page']로 지정된 페이지를 주소에 추가할지 여부를 지정하는 불리언 값입니다.예시:
echo link_tag('css/mystyles.css'); // gives <link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />
추가 예시:
echo link_tag('favicon.ico', 'shortcut icon', 'image/ico'); // <link href="http://site.com/favicon.ico" rel="shortcut icon" type="image/ico" /> echo link_tag('feed', 'alternate', 'application/rss+xml', 'My RSS Feed'); // <link href="http://site.com/feed" rel="alternate" type="application/rss+xml" title="My RSS Feed" />
또한 연관 배열을
link()함수에 전달하여 모든 속성과 값을 완전히 제어할 수 있습니다:$link = array( 'href' => 'css/printer.css', 'rel' => 'stylesheet', 'type' => 'text/css', 'media' => 'print' ); echo link_tag($link); // <link href="http://site.com/css/printer.css" rel="stylesheet" type="text/css" media="print" />
- ul($list[, $attributes = ''])¶
- 매개변수:
$list (
array) – 목록 항목$attributes (
array) – HTML 속성
- 반환:
HTML 형식의 순서 없는 목록
- 반환 형식:
string
단순 또는 다차원 배열에서 순서 없는 HTML 목록을 생성할 수 있습니다. 예시:
$list = array( 'red', 'blue', 'green', 'yellow' ); $attributes = array( 'class' => 'boldlist', 'id' => 'mylist' ); echo ul($list, $attributes);
위 코드는 다음을 생성합니다:
<ul class="boldlist" id="mylist"> <li>red</li> <li>blue</li> <li>green</li> <li>yellow</li> </ul>
다차원 배열을 사용하는 더 복잡한 예시:
$attributes = array( 'class' => 'boldlist', 'id' => 'mylist' ); $list = array( 'colors' => array( 'red', 'blue', 'green' ), 'shapes' => array( 'round', 'square', 'circles' => array( 'ellipse', 'oval', 'sphere' ) ), 'moods' => array( 'happy', 'upset' => array( 'defeated' => array( 'dejected', 'disheartened', 'depressed' ), 'annoyed', 'cross', 'angry' ) ) ); echo ul($list, $attributes);
위 코드는 다음을 생성합니다:
<ul class="boldlist" id="mylist"> <li>colors <ul> <li>red</li> <li>blue</li> <li>green</li> </ul> </li> <li>shapes <ul> <li>round</li> <li>suare</li> <li>circles <ul> <li>elipse</li> <li>oval</li> <li>sphere</li> </ul> </li> </ul> </li> <li>moods <ul> <li>happy</li> <li>upset <ul> <li>defeated <ul> <li>dejected</li> <li>disheartened</li> <li>depressed</li> </ul> </li> <li>annoyed</li> <li>cross</li> <li>angry</li> </ul> </li> </ul> </li> </ul>
- ol($list, $attributes = '')¶
- 매개변수:
$list (
array) – 목록 항목$attributes (
array) – HTML 속성
- 반환:
HTML 형식의 순서 있는 목록
- 반환 형식:
string
ul()과 동일하지만 <ul> 대신 순서 있는 목록에 <ol> 태그를 생성합니다.
- meta([$name = ''[, $content = ''[, $type = 'name'[, $newline = "\n"]]]])¶
- 매개변수:
$name (
string) – 메타 이름$content (
string) – 메타 내용$type (
string) – 메타 유형$newline (
string) – 줄바꿈 문자
- 반환:
HTML 메타 태그
- 반환 형식:
string
메타 태그를 생성할 수 있습니다. 함수에 문자열, 단순 배열 또는 다차원 배열을 전달할 수 있습니다.
예시:
echo meta('description', 'My Great site'); // Generates: <meta name="description" content="My Great Site" /> echo meta('Content-type', 'text/html; charset=utf-8', 'equiv'); // Note the third parameter. Can be "charset", "http-equiv", "name" or "property" // Generates: <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> echo meta(array('name' => 'robots', 'content' => 'no-cache')); // Generates: <meta name="robots" content="no-cache" /> $meta = array( array( 'name' => 'robots', 'content' => 'no-cache' ), array( 'name' => 'description', 'content' => 'My Great Site' ), array( 'name' => 'keywords', 'content' => 'love, passion, intrigue, deception' ), array( 'name' => 'robots', 'content' => 'no-cache' ), array( 'name' => 'Content-Type', 'type' => 'http-equiv', 'content' => 'text/html; charset=utf-8' ), array( 'name' => 'UTF-8', 'type' => 'charset' ) ); echo meta($meta); // Generates: // <meta name="robots" content="no-cache" /> // <meta name="description" content="My Great Site" /> // <meta name="keywords" content="love, passion, intrigue, deception" /> // <meta name="robots" content="no-cache" /> // <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> // <meta charset="UTF-8" />
- doctype([$type = 'html5'])¶
- 매개변수:
$type (
string) – Doctype 이름
- 반환:
HTML DocType 태그
- 반환 형식:
string
문서 유형 선언(DTD)을 생성할 수 있습니다. 기본값은 HTML 5이지만 다양한 doctype을 사용할 수 있습니다.
예시:
echo doctype(); // <!DOCTYPE html> echo doctype('html4-trans'); // <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "https://www.w3.org/TR/html4/strict.dtd">
다음은 doctype 선택 목록입니다. application/config/doctypes.php에서 설정할 수 있습니다.
Document type
Option
Result
XHTML 1.1
xhtml11
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “https://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
XHTML 1.0 Strict
xhtml1-strict
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
XHTML 1.0 Transitional
xhtml1-trans
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
XHTML 1.0 Frameset
xhtml1-frame
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Frameset//EN” “https://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd”>
XHTML Basic 1.1
xhtml-basic11
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML Basic 1.1//EN” “https://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd”>
HTML 5
html5
<!DOCTYPE html>
HTML 4 Strict
html4-strict
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “https://www.w3.org/TR/html4/strict.dtd”>
HTML 4 Transitional
html4-trans
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “https://www.w3.org/TR/html4/loose.dtd”>
HTML 4 Frameset
html4-frame
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Frameset//EN” “https://www.w3.org/TR/html4/frameset.dtd”>
MathML 1.01
mathml1
<!DOCTYPE math SYSTEM “https://www.w3.org/Math/DTD/mathml1/mathml.dtd”>
MathML 2.0
mathml2
<!DOCTYPE math PUBLIC “-//W3C//DTD MathML 2.0//EN” “https://www.w3.org/Math/DTD/mathml2/mathml2.dtd”>
SVG 1.0
svg10
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.0//EN” “https://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd”>
SVG 1.1 Full
svg11
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1//EN” “https://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd”>
SVG 1.1 Basic
svg11-basic
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1 Basic//EN” “https://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd”>
SVG 1.1 Tiny
svg11-tiny
<!DOCTYPE svg PUBLIC “-//W3C//DTD SVG 1.1 Tiny//EN” “https://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd”>
XHTML+MathML+SVG (XHTML host)
xhtml-math-svg-xh
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN” “https://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd”>
XHTML+MathML+SVG (SVG host)
xhtml-math-svg-sh
<!DOCTYPE svg:svg PUBLIC “-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN” “https://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd”>
XHTML+RDFa 1.0
xhtml-rdfa-1
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML+RDFa 1.0//EN” “https://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd”>
XHTML+RDFa 1.1
xhtml-rdfa-2
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML+RDFa 1.1//EN” “https://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd”>