CakePHP Lightbox Helper
Made a helper to output lightbox compatible links, since the core HTML helper was not working. Stick the following code in app/view/helpers/lightbox.php:
class LightboxHelper extends AppHelper {
var $helpers = array('Html');
function img($thumb, $full, $imgAttributes = array(), $linkAttributes = array()) {
$defaultLinkAttributes = array('rel'=>'lightbox');
$linkAttributes = array_merge($defaultLinkAttributes, $linkAttributes);
$thumb = $this->Html->image($thumb, $imgAttributes);
if (strpos($full, '://') === false) {
$full = $this->Html->webroot(IMAGES_URL . $full);
}
return $this->Html->output(sprintf($this->Html->tags['link'], $full, $this->Html->_parseAttributes($linkAttributes), $thumb));
}
}
Then you can use it from your views, after including it in your controller’s $helpers array, like the following:
echo $lightbox->img('somethumb.jpg', 'somefullimage.jpg');
January 13th, 2009 at 4:42 pm
Hi!
I have my lightbox setup and I’m using your helper –
I see all the js / css loading (through firebug) –
but when I click on the image – I simply get forwarded to a page where only the image shows..(i.e. no pop-up/lightbox)
Any clues what this has to do with?
I use lightbox on non cakephp sites without a problem, and I see cakephp generating the same code – still not sure why it doesn’t work..
thoughts?
May 5th, 2010 at 6:44 pm
I’ve tried your code but get a complain about imgController missing? Any suggestion why would that happen?
May 5th, 2010 at 8:09 pm
sorry for previous message – I’ve made a mistake deleting the folder with controllers that were required by other apps
Any help?
But my lightbox effect is not working even after following your suggested steps. Just opens the image in a parent window not even popup style
June 7th, 2010 at 4:52 am
Good morning, thanks for the interesting article? Is your blog a free theme or custom? I am interested by your site. Is it feasible to include this article on one of my sites?, i will of course link to this blog. regards