Background:
I want to render this:
<a href="javascript:myfunction('Somevar')"><img src="some.png" width="20" height="20" border="0" /></a>
in a cakephp app. Note: this link is not associated with a model at all, it’s just part of a form going off-site.
I’m unsure of how to proceed: I’ve seen this on the cakephp site, but
with all that goes on in cake, I’m not sure about the whole javascript calling business. What’s the best way to create such a thing?
EDIT: Cake 1.2 is what I am working with.
It’s no problem at all to pass a Javascript function as the second parameter to
HtmlHelper::link. This should do the trick:This invokes
HtmlHelper::link, passing an image (generated byHtmlHelper::image) as the HTML around which to wrap the<a />, the Javascript function as the link’s action, and informing Cake not to escape the HTML you passed.Update:
Here’s the snippet for Cake 1.2:
The final
falseparameter ofHtmlHelper::linkinstructs Cake not to escape the HTML.