sn4k3
(Tiago Caza)
December 8, 2010, 6:22pm
1
Hi, i try to search and after many tests i can’t get it work, documentation doesn’t provide samples
i have:
<?php
echo CGoogleApi::init();
echo CHtml::script(
CGoogleApi::load('jquery','1.4.4')/* . "\n" .
CGoogleApi::load('jquery.ajaxqueue.js') . "\n" .
CGoogleApi::load('jquery.metadata.js')*/
); ?>
<?php
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false,
'jquery.min.js'=>false,
'/resources/js/hoverIntent.js'=>'/resources/js/all.js',
'/resources/js/jquery.cycle.all.min.js'=>'/resources/js/all.js',
'/resources/js/jquery.easing.1.3.js'=>'/resources/js/all.js',
'/resources/js/superfish.js'=>'/resources/js/all.js',
'/resources/js/supersubs.js'=>'/resources/js/all.js',
);?>
google jquery got render but scriptMap scripts doesnt
whats wrong?
thanks
You only need to use the scriptMap if you want to tell Yii that scripts are in a different place than they normally would be. For example if you don’t want Yii to use it’s bundled jquery file but supply your own.
If you want to include a script in your site simply use
Yii::app()->clientScript->registerScriptFile('/path/to/script/file.js');
// As if 1.1.5 (I believe, or 1.1.4?) this is chainable:
Yii::app()->clientScript
->registerScriptFile('/path/to/script/file.js')
->registerScriptFile('/path/to/another/script/file.js');
iivano71
(Igor Zg1987)
December 8, 2010, 11:38pm
3
Hi, i try to search and after many tests i can’t get it work, documentation doesn’t provide samples
i have:
<?php
echo CGoogleApi::init();
echo CHtml::script(
CGoogleApi::load('jquery','1.4.4')/* . "\n" .
CGoogleApi::load('jquery.ajaxqueue.js') . "\n" .
CGoogleApi::load('jquery.metadata.js')*/
); ?>
<?php
$cs=Yii::app()->clientScript;
$cs->scriptMap=array(
'jquery.js'=>false,
'jquery.min.js'=>false,
'/resources/js/hoverIntent.js'=>'/resources/js/all.js',
'/resources/js/jquery.cycle.all.min.js'=>'/resources/js/all.js',
'/resources/js/jquery.easing.1.3.js'=>'/resources/js/all.js',
'/resources/js/superfish.js'=>'/resources/js/all.js',
'/resources/js/supersubs.js'=>'/resources/js/all.js',
);?>
google jquery got render but scriptMap scripts doesnt
whats wrong?
thanks
script map is not for renderning files , first you have to attach it like example below ,than you have to map it,
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/resources/js/hoverIntent.js');
Yii::app()->clientScript->scriptMap=array(Yii::app()->baseUrl.'/resources/js/hoverIntent.js'=>Yii::app()->baseUrl.'/resources/js/all.js');
script map is not for renderning files , first you have to attach it like example below ,than you have to map it,
Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl.'/resources/js/hoverIntent.js');
Yii::app()->clientScript->scriptMap=array(Yii::app()->baseUrl.'/resources/js/hoverIntent.js'=>Yii::app()->baseUrl.'/resources/js/all.js');
Wait, what?
Just calling the CClientScript::registerScriptFile is enough, no need to set the map in this case.
See the documentation (or my previous post) see what you actually need the scriptMap for.
iivano71
(Igor Zg1987)
December 8, 2010, 11:50pm
5
ScallioXTX:
Wait, what?
Just calling the CClientScript::registerScriptFile is enough, no need to set the map in this case.
See the documentation (or my previous post) see what you actually need the scriptMap for.
You didn`t get the point what he wont, he wont to map js files ,he need first to attach it then map it
In that case he should first map it, and then register it.
Otherwise it’s like saying “Register script xyz, oh yeah, and by xyz I mean abc”.
Instead you say "Script xyz should now be known as abc, register script xyz", which will register abc.
Try it if you don’t believe me.