user1327
user1327

Reputation: 948

How to write this code with cakephp 2.2.1 html helper?

I probably made a monster when writing an echo for outputting generated links :( I don't understand how to concatenate all this params when using HtmlHelper. I read article about it twice but don't get it.

My code is:

echo "<a href=\"/img/filmography/" . $movie['Film']['frameset'] . 
     "_frame_" . $i . ".jpg\"" . "rel=\"lightbox[" . $movie['Film']['id'] . 
     "]\"" . " title=\"\">" 

     . "<img src=\"/img/filmography/thumb/" . $movie['Film']['frameset'] . 
     "_frame_" . $i . ".jpg\"" . "alt=\"pic from " . $movie['Film']['title'] . 
     "\"" . "/></a>";

What I want to achieve in HTML:

   <a href="/img/filmography/movie_frame_1.jpg" rel="lightbox[1]" title="">
        <img src="/img/filmography/thumb/movie_frame_1.jpg" 
             alt="pic from some movie"/>
   </a>

Upvotes: 0

Views: 302

Answers (2)

Justin John
Justin John

Reputation: 9616

I think, this will do for you..

$path = sprintf("/filmography/thumb/%s_frame_%s.jpg", $movie['Film']['frameset'], $i);
echo $this->Html->link($this->Html->image($path, array(    "alt" => "pic from " . $movie['Film']['title'])) , '/img/filmography/'. $movie['Film']['frameset'] . '_frame_' . $i . '.jpg',  array('escape' => false, 'rel' => 'lightbox[' . $movie['Film']['id'] . ']'));

Upvotes: 2

Abid Hussain
Abid Hussain

Reputation: 7762

use this:-

$frame_thumbnail = "img/filmography/" . $movie['Film']['frameset'] ."_frame_" . $i . ".jpg";
$frame_full = "img/filmography/thumb/" . $movie['Film']['frameset'] . "_frame_" . $i . ".jpg";

$alt= "pic from " . $movie['Film']['title'];
$real = "lightbox[" . $movie['Film']['id'] ."]";


$thumb = $html->image($frame_thumbnail, array('alt'=>$alt));
$full = $html->image($frame_full, array('alt'=>$alt));

echo $this->Html->link($thumb,$full,array('escape' => false, 'rel' =>$real));

Or read this htmlHelper & link

http://api.cakephp.org/class/html-helper#method-HtmlHelperlink

http://book.cakephp.org/view/1442/link

Upvotes: 0

Related Questions