2010-02-07 3 views
0

을 편집하여 케이크 틀에 로고를 추가, 그럼 내가 비싼 모두 자원을 HTML 헬퍼입니다 사용하여 실제 이미지 파일 자체내가 이미지에 대한 코드를 배치해야합니까 default.ctp

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
    <?php echo $html->charset(); ?> 
    <title> 
     <?php __('neigh*borrow'); ?> 
     <?php echo $title_for_layout; ?> 
    </title> 
    <?php 
     echo $html->meta('icon'); 

     echo $html->css('cake.generic'); 

     echo $scripts_for_layout; 
    ?> 
</head> 
<body> 
    <div id="container"> 
     <div id="header"> 
      <h1><?php echo $html->link(__('neigh*borrow, the communty for borrowing things you need when you need them. NYU students interested in participating in the BETA should enter an item they would like to borrow along with their .NYU.EDU email address. ', true), 'http://cakephp.org'); ?></h1> 
     </div> 
     <div id="content"> 

      <?php $session->flash(); ?> 

      <?php echo $content_for_layout; ?> 

     </div> 
     <div id="footer"> 
      <?php echo $html->link(
        $html->image('cake.power.gif', array('alt'=> __("CakePHP: the rapid development php framework", true), 'border'=>"0")), 
        'http://www.cakephp.org/', 
        array('target'=>'_blank'), null, false 
       ); 
      ?> 
     </div> 
    </div> 
    <?php echo $cakeDebug; ?> 
</body> 
</html> 

답변

-2

을 둘 것입니다 어디에 무기력하다 : 더 많은 코드를 작성하게 될 것이다.

평범한 HTML로 원하는 것을 작성하면 어떨까요?

+0

내가 html로 작성한 경우에도 - 이미지를 넣을 곳은 어디입니까 ... 케이크의 "이미지"는 무엇입니까? – adam

+2

webroot/images 디렉토리에서. – metrobalderas

+0

HtmlHelper는 더 비싸지 만, 다시 말하면 입력 내용을 저장하지 않는 것입니다. 요점은 당신에게 이미지에 대한 올바른 URL을 제공하는 것입니다. 하드 코딩 된 URL을 유지하기 위해 노력하십시오. 상대 URL은 레이아웃에서 작동하지 않으며 다른 컴퓨터에 배포 한 경우 절대 URL이 깨질 수 있습니다. 최소한 Webroot 디렉토리에 정의 된 상수를 사용해야 만합니다. 그런 다음 HtmlHelper를 사용하여 결과 HTML/PHP 코드를 피할 수 있습니다. 속도에 대해 염려하는 경우 적절한 캐싱을 조사하십시오. – deceze

3

그것을 위해 출력 (배치 포함) 뷰의 아무 곳이나 이미지 태그를 HtmlHelper을 폴더 /app/webroot/img/에 이미지를 넣고 사용 (또한,이 코드 약간의 서식을 유용 할 수 있습니다) :

// outputs tag for /webroot/img/myimage.jpg 
echo $html->image('myimage.jpg'); 

// outputs tag for /webroot/img/subfolder/otherimage.jpg 
echo $html->image('subfolder/otherimage.jpg'); 

// outputs tag for /webroot/img/myimage.jpg with an alt attribute 
echo $html->image('myimage.jpg', array('alt' => 'My Text for My Image')); 

앱을 휴대하고 관리하기 쉬운 상태로 유지하려면 HtmlHelper을 사용하여 올바른 URL이 포함 된 이미지 태그를 이미지에 출력해야합니다. 기본적으로 Cake : Stylesheets, Images, Links, URL에 관련된 모든 URL에 사용됩니다.

1

Adam, Deceze에서 언급했듯이 이미지는 일반적으로 webroot 아래의 img 폴더에 있습니다. 이렇게하면 쉽게 액세스 할 수 있습니다. 당신은 directory_separator으로 웹 루트 아래에 다른 폴더에 넣어 수 있지만, 다음 경로 스펙이 선행되어야한다

//folder = webroot/myImages 
echo $html->image('/myImages/image.png'); 

이 모두는 매우 유용 얻을 수 whenyou 시작 자바 스크립트와 CSS를 포함 :

echo $javascript->link('someJavascript',false); 
echo $html->css('bigStyles',true); 

false<head>...</head> true에 스크립트 또는 스타일을 포함 시키면 php 문이 발생하는 시점에 스크립트가 포함됩니다.

javascript 및 css 확장이없는 것에 유의하십시오. 당신이 링크로 이미지를 사용하려는 경우 우리는이 주제에있는 동안

, 당신은 링크 문에 탈출을 비활성화해야, 즉 :

$eye = $html->image('eye.jpg'); 
// the final false disables escaping. 
echo $html->link($eye,$url,array('target'=>'_blank'),false,false); 

편집 : 나는 ' d는이 링크를 포함하여 의도 : http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf 이것은 편리하지만 불만스러운 불완전한 빠른 참조입니다.

+2

이미지를 연결하려면 더 간단한 구문이 있습니다 :'$ html-> image ('image.jpg', array ('url'=> $ url))'. 링크에 속성을 추가하려면 이스케이프가 아닌 구문을 사용해야하지만 대부분의 링크에서는이 방법이 좋습니다. :) – deceze

+0

동의하지만 항상 진행할 때 상황이 바뀌는 것을 발견하면 항상 전체 구문을 사용합니다. – Leo

관련 문제