My folder structure:
-MyProject
--assets
--css
--fonts
--images
--js Get an error! cannot find this folder?
--protected
--themes
--index.php
What should I change in my urlManager, so the project can find my self created folders?
This is how my urlmanager looks now:
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
In my view I have included:
Yii::app()->clientScript->registerScriptFile('js/MYSCRIPT.js');
you can point to that folder like
$jsFolder = Yii::app()->homeUrl . 'js/';
$imagesFolder = Yii::app()->homeUrl . 'images/';// will give you : "/localhost/MyProject/images/"
You should use
Yii::app()->clientScript->registerScriptFile(Yii::app()->request->baseUrl . '/js/YOUR-SCRIPT.js', CClientScript::POS_HEAD);
to embed your script in layout. You can however access your script from your view with this part:
Yii::app()->request->baseUrl . '/js/YOUR-SCRIPT.js';
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.