简体   繁体   中英

Including CSS and JS files in Yii Framework

I met a problem while trying to include CSS and JS files by registerScriptFile and registerCssFile method in Yii Framework.

I gathered all CSS and JS files which put in head tag,

<script type="text/javascript" src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.ad-gallery.js"></script>   
<link href="<?php echo Yii::app()->theme->baseUrl; ?>/css/jquery.ad-gallery.css"rel="stylesheet" type="text/css"></link>

moved them into header widget and replaced with these code:

Yii::app()->getClientScript()->registerCssFile(Yii::app()->theme->baseUrl.'/css/jquery.ad-gallery.css');
Yii::app()->getClientScript()->registerScriptFile(Yii::app()->theme->baseUrl.'/js/jquery.ad-gallery.js', CClientScript::POS_HEAD);

CSS files turned out without any problem. However, JS files seemed to fail and encounter error:

Uncaught TypeError: Object [object Object] has no method 'fancybox'

Did I do anything wrong?

The "jquery.ad-gallery.js" file may be connected to the page before jquery. Try removing the option "POS_HEAD" or replace it with "POS_END".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM