Hi, everyone.
I’m new to Yii. I have a question regarding the way of loading a javascript file inside my view. For some reasons, I can not use the default jquery-ui or jquery script from Yii. So I come up with these lines inside my themes/awesome_theme/layouts/main.php
[html]…
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.min.js"></script>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/jquery.ui.custom.js"></script>
<script src="<?php echo Yii::app()->theme->baseUrl; ?>/js/bootstrap.min.js"></script>
</body>
</html>[/html]
I want to include another javascript file to my view, for example from themes/awesome_theme/js/my_script.js, this way…
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/my_script.js',CClientScript::POS_END);?>
The script is running well, except I can not include another PHP tag inside my .js code. If I want to include some PHP scripts, I need to include it inside a view. I’m wondering what is the best practice/way to do it. I can move the
<script src=""></script>
inside my
<head></head>
to solve this, but it will make the page load slower.
Is there any other solution to this? Thank you and please forgive my English.