问题
I have a problem. I don't know where to put jQuery EasyUI in CakePHP? Which folder?
Do I use it like a helper?
Do I have to put something like:
var $helpers = array('jQuery');
Do I have to put some in view?
Thank you so much for your help always. :)
Edit:
And if you can give me some online tutorials with jQuery EasyUI with CakePHP 2.x. (I already Google it.) :D
回答1:
In CakePHP javascript files are stored in app/webroot/js/.
You then can include them in the layout by calling
echo $html->script('jquery-1.7.2.min.js');
You can then write your javascript code in either the view or another external js file.
回答2:
As this question is for CakePHP 2.x the correct answer is:
echo $this->Html->script('jquery-1.7.2.min');
Notice that there is no extension for the JavaScript file. The script() function of the HtmlHelper includes script files from the app/webroot/js forlder. You can also load multiple script files:
echo $this->Html->script(array(
'jquery/jquery-1.7.2.min',
'jquery/jquery-ui-1.8.19.custom.min',
'jquery/jquery.tooltip.min',
'raphael',
'main',
'screen'
));
Script dependance and precedence also have a role here. This means that if say scriptA.js depends on scriptB.js, the later must be loaded first:
echo $this->Html->script(array(
'scriptB',
'scriptA'
));
When you're loading a plugin of jQuery you must watch over this as well. Notice that in the example I gave for loading multiple script files shows this.
回答3:
Upload the jQuery & jQuery EasyUI source code to your /app/webroot/js directory
Link to them in your layout (if you want it included in all your pages) or in individual views with:
<?php $this->Html->script(array('jquery.js', 'jquery-easyui.js'), array('inline'=>false)); ?>
(Replace jquery.js and jquery-easyui.js filenames with the actual filenames)
One you have the libraries loading properly (use Firebug to check ;-), you should be able either with inline scripts (not recommended) or by loading external scripts:
<?php $this->Html->script(array('jquery.js', 'jquery-easyui.js', 'myscript.js'), array('inline'=>false)); ?>
Note: The order you include them is important.
回答4:
echo $html->script('jquery-1.7.2.min');
来源:https://stackoverflow.com/questions/10708599/cakephp-2-x-jquery-easyui-how-to-put-jquery-easyui-in-cakephp-2-x