where do i put the code for the image, then where would i put the actual image file itself
<!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 f开发者_开发百科ramework", true), 'border'=>"0")),
'http://www.cakephp.org/',
array('target'=>'_blank'), null, false
);
?>
</div>
</div>
<?php echo $cakeDebug; ?>
</body>
</html>
Put the image in the folder /app/webroot/img/
and use the HtmlHelper
anywhere in the view (including the layout) to output an image tag for it:
// 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'));
To keep your app portable and maintainable, you'll need to use the HtmlHelper
to output the image tag with the correct URL to the image. That goes for basically everything URL related in Cake: Stylesheets, Images, Links, URLs in general.
Adam, as noted by Deceze, images generally go in the folder img, below webroot. This way access is easy. You can put them in other folders below webroot, but then the path spec should be preceded by a directory_separator:
//folder = webroot/myImages
echo $html->image('/myImages/image.png');
This all gets quite useful whenyou start including javascript and css:
echo $javascript->link('someJavascript',false);
echo $html->css('bigStyles',true);
false
will cause the script or styles to be included in the <head>...</head>
true
will cause them to be included at the point the php that statement occurs.
Note the absence of extensions for javascript and css.
While we're on this subject, if you want to use an image as a link, you need to disable the escaping on the link statement, viz:
$eye = $html->image('eye.jpg');
// the final false disables escaping.
echo $html->link($eye,$url,array('target'=>'_blank'),false,false);
edit: I'd intended including this link: http://cakephp.org/files/Resources/CakePHP-1.2-Cheatsheet.pdf which is a handy but frustratingly incomplete quick reference.
Using the html helper is both resource expensive and helpless: you'll end up writing more code.
Why don't you simply write what you need in plain HTML?
(Also, it might be useful formatting a little your code)
精彩评论