I want to load the JS
file in view to avoid heavy-loading of my application. I am using this JS
file for CgrdView
in view. SO i tried this:
Yii::app()->clientScript->registerScriptFile(
Yii::app()->baseUrl.'/assets/9d419b82/jquery.ba-bbq.js?v=1.0.127'
);
in My view header. But i am getting the error:Uncaught ReferenceError: jQuery is not defined As stated, i want to load jquery.ba-bbq.js file in view for CgriView, but i am not able to load that. Instead, i use following, but dont know is the efficient way to load or not.
<script src="/assets/9d419b82/jquery.ba-bbq.js?v=1.0.127" type="text/javascript"></script>
And is working when i load that in layouts, but this is not the efficient way.
FYI: I am working with cgridview
search-box to post the search-box entry to my controller.
The bbq script is available as a core script and registering it will also load jquery.js. So to use bbq you simply need to do this:
Yii::app()->clientScript->registerCoreScript('bbq');
The assets folder is dynamic in nature, and it is used to store scripts, css, images in a web-accessible directory. It is automatically populated by the various Yii widgets, and also when you call registerCoreScript
. Because of these reasons and more you shouldn't be relying on the assets folder to include js, css, images, but instead let the framework include it for you.
I couldn't find a list of the core packages in the docs, but it can be seen in the source file: framework/web/js/packages.php.
Incase you want this in a view with a CGridView
, then let me tell you that CGridView
loads this script automatically, and you don't have to register it again.