Display images in CakePHP

Today I face a problem as a beginner of CakePHP …How can I display image button with link in Cake. I wanted to use images as my buttons to edit and delete records and  navigate the admin pages.

1. Have to use HTML Helpers Image and Link, and we shall combine this 2. The CakePHP link helper is a handy tool to create links in your application. Here is the basic syntax:

<?php echo $html->link(’help!’,’/help’); ?>

And there’s a helper for creating images, too:

<?php echo $html->image(’add.gif’); ?>

Show HTML code of the image as the link:

<?php echo $html->link($html->image(’add.gif’),’/customers/add’)?>

2. For Image,
Syntax:

$html->image(string $path, array $htmlAttributes, boolean $return = false);

Example:

$html->image(’/img/images/cancel.png’, array(’class’ => ’save_button’));
3. For Link, the Syntax:

$html->link(string $title, string $url, array $htmlAttributes, string $confirmMessage = false, boolean $escapeTitle = true, boolean $return = false);

Example:

$html->link(’SAVE’, ‘/registers’, array(), false, false, false);

4. So to make an image clickable,

<?php echo $html->link($html->image(’/img/images/cancel.png’,array(’class’ => ’save_button’)), ‘/registers’, array(), false, false, false); ?>

And the best code is:
<?php echo $html->link($html->image(’add.gif’),’/customers/add’,array(’escape’=>false))?>

Hope it will help you to save time.

Advertisements

6 Responses

  1. Hi there,

    I am a PHP newbie and found your article quite useful. Thanks for sharing the stuff and keep sharing in future too.

    Best Regards,

    Adnan Siddiqui

  2. I am a freelancer. I have more clients in USA.

    I need more developer.

    Alam

  3. I want to insert multiple image and then display one image and create a link more image, when click on more image then display another images.

    Submitted by,
    N. Alam
    Freelancer

  4. I love your blog.. very nice colors & theme. Did you make this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from. kudos

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: