popup with javascript in CakePHP 1.2 and pages controller
update: More on the XHTML technique popup
I wanted to make a simple popup in my latest Cake app, and so needed to set a blank layout just from looking at the URL, as the page was essentially static that I was going to pop up.
e.g. then my little popup URL caller (hyperlink
) would look like
for a link to http://example.com/pages/coverage/layout:popup
echo $html->link('my popup linky',
array('controller'=>'pages',
'action'=>'coverage',
'layout'=>'popup')
,array(
'onclick'=>
'return Popup.open({url:this.href});'));
that’s the cake url syntax parser doing all the magic there - as in 1.2 the new named paramaters, where one passes the info via GET separated by a : is nimbly handled by just taking its key in the array — e.g. ‘layout’ in this case resolves to popup.
Then I made a quick popup in my layouts folder. It’s totally blank.
But the pages controller display() action usually calls ‘default’ layout. I could simply just make a action in another controller, but this is not very DRY.
So I copied pages_controller to my controllers (overloading the typical one), then added a little switch statement:
// set a custom layout
switch ($this->passedArgs['layout']) {
case 'popup':
$layout = 'popup';
break;default:
$layout = 'default';
break;
}
// change the final line too:
$this->render(join('/', $path),$layout);
the javascript is a slick script that is accessible and uses prototype:
you can also pass it options like width:300 etc so that your popup is not a jumbotron popup.
The magic of CakePHP and Prototype
this is my first cake post, might do some more hopefully soon…
April 2nd, 2008 at 9:46 pm
Hi, I did your code but it DON’T POP UP, it just act like a normal link
can you help me?-