views:

181

answers:

3

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"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<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>
A: 

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)

metrobalderas
even if i wrote it in html-- where would i put the image itself... what is the "images" equivalent in cake
adam
In the webroot/images dir.
metrobalderas
The HtmlHelper may be more expensive, but then again its point is not to save you typing. Its point is to give you the right URL to the image. Good luck in trying to maintain hardcoded URLs. Relative URLs will simply not work in the layout, absolute URLs may break if you ever deploy to a different machine. You'll have to at least use the defined constants to the webroot directory, but then you may just as well use the HtmlHelper to avoid the resulting HTML/PHP hodgepodge. Look into proper caching if you're that concerned about speed.
deceze
I don't know why I'm being downvoted.Your point is valid, but I don't think it stands as a constant. But for what I understand about CakePHP is that each app should reside in its own domain / subdomain. Example: domain1.com should be in public_html/domain1, mydomain.com, in public_html/mydomain.That way, you don't really have to worry about hardcoding. But whatever, I'm just trying to help, and my answer seems to have helped the OP.
metrobalderas
@metro I downvoted your answer because it's bad advise, as simple as that. Don't take it personally, but please learn from it. :) Cake apps don't need to reside in their own subdomain, they can perfectly well exist in subdirectories. To keep flexibility for different environments (even just local development vs. production server), you should never hardcode URLs. And that goes for web apps in general, not just Cake.
deceze
@metro BTW, this is all IMHO, but I believe it to be true enough to justify a downvote. :)
deceze
+3  A: 

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.

deceze
+1  A: 

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.

Leo
To link images there's a simpler syntax: `$html->image('image.jpg', array('url' => $url))`. If you want to put attributes on the link you'll still have to use your non-escaping syntax, but for most links this is a nicer way. :)
deceze
Agreed, but I always use the full syntax from the outset as I find things usually change as I proceed.
Leo