Where To Place External Files

Hi, when I use external files (CSS, PHP, third party…) I don’t know where to place. Where is it the right and clean place.

suppose that main folder is where I’ve assets, css, images, protected…

  1. In this path I inserted my JS folder with all jquery, bootstrap, lightbox, showloading etc… JS files. Is this OK? (sometimes I’ve CSS and image sub-folder for files linked to JS scripts)

  2. In this path I inserted a server/php folder where I places UploadHandlder.php files and in /img sub-folder … the images linked to this script

  3. in this path I inserted an “upload” folder where I’ll save all images uploaded by users

  4. Question: I’ve CSS folder and Themes folder. When insert CSS files in Theme (css sub-folder of theme) and when in CSS folder placed in main path?

Thanks for help me!


1)Put your All CSS in CSS folder and call them in main layout.

<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/admin_main.css" />

2)Js to all in js folder and call them

<script src="<?php echo Yii::app()->request->baseUrl; ?>/js/jquery.min.js"></script>

3)Finally create the upload folder in root and upload in image


					$url ='http://'.$_SERVER['HTTP_HOST']. Yii::app()->baseUrl;


					$model->image = CUploadedFile::getInstance($model, 'image');




Best Regards,

Ankit Modi

The /css folder is provided as a default folder and used by ‘blueprint css’ framework that is included with Yii. On regular development practices, you’ll create your own theme folder under /themes and store everything there, probably ignoring /css.

I typically create a special directory with user uploaded content, in parallel to /themes, /protected and so on. I don’t wish to upload the user content into the theme folder and see no reason to do so (on the contrary -t he theme is ‘my’ provided theme folder and should remain clean).

Best practices guidelines would recommend keeping /protected… protected and not accessible for write or read directly from the web. Other than that, consider separation between your resources and user uploaded resources. This is good for backup purposes as well.

This is all up to you though and what you decide to do on your project.

Thanks for your replies!


Main CSS folder could not be used (not considered), and I could use CSS folder that I’ve in /theme folder. Right?

Is OK to use JS folder (in main path) for save all JS used in web app

Could be that some JS have own CSS files, and I’ll have specified subfolders for css and images linked to JS files in /JS/** path

What about new PHP script that I want to use in my webapp?

Suppose script for manage specified upload … or other features (payment file etc…).

What to do with these? Where place and how to call?


Regarding JS, you can definitely go with the suggested design. Be advised also that Yii shines when it comes to modularity. Hopefully, sooner or later you’ll start organizing your code into packages - extensions, modules, etc. Those packages, can carry their own ‘resources’ and those resources can be ‘published’ by Yii assets manager. Have a look in this well written wiki article for more details on the assets manager. Using such methodology, each package can carry its own basic css, js, images (etc) resources that are published by decision made in the package itself (for example, when a module or a widget contained within a module knows that now some resources should be referenced by the user - then it ‘publishes’ them).

Not sure I fully understood you ‘php script’ question. I guess this is plain functionality you refer to, rather than css, js, etc. In that case, its a different ball game and this deserves a new question in which you’d better describe that PHP code/functionality needed and ask for recommendations on how to pack it.