Using scripts_for_layout in plugin helper method
i w开发者_JAVA百科riting my menu plugin helper (similar to cakemenu) and i want to you js and css related to my plugin with in scripts_for_layout
how to add them to plugin helper method?
class AdminmenuHelper extends AppHelper {
var $helpers = array('Html', 'Javascript');
function show() {
$output = '
<ul>
<li><a href="/users/dashboard"><img src="/img/admin/icons/home.png" border="0" />;02=0O</a></li>
<li><a href="/admin/products/"><img src="/img/admin/icons/document.png" border="0" />@>4C:F8O</a></li>
<li><a href="/admin/categories/"><img src="/img/admin/icons/document.png" border="0" />0B53>@88</a></li>
<li><a href="/users/logout"><img src="/img/admin/icons/door-open-in.png" border="0" />KE>4</a></li>
</ul>
';
return $output;
}
In your helper, you can add one of these 2 methods
#1
function beforeRender() {
$html = new HtmlHelper();
$html->script('custom', false);
}
#2
function beforeRender() {
$view =& ClassRegistry::getObject('view');
$view->addScript('<script type="tex/javscript" src="' . Router::url('/js/custom.js') . '"></script>');
}
#2 is lighter because it does not need to instantiate a new helper, but you have to write te entire javascript tag. It’s up to you to choose which one you like more.
精彩评论