Yiiboilerplate Common Htaccess

Hi guys

The boilerplate documentation encourage you to put files that are shared between frontend and backend in the common directory.

However, the common directory contains an .htaccess file with "deny from all".

So how do you access your files in common?

I see the index.php file uses include_once, but that is used for individual files, not for an entire directory.


in ur backend/frontend config/main.php

'import' => array(





It’s just because there should be no files in “common” directory that should be accessed directly from the end user. You will find the same .htaccess in “framework” directory of Yii.

[color="#006400"]/* moved from General Discussion */[/color]

Hi Lal Zada

I added myfiles folder:

'import' => array( 






But, it still does not work, unless I put a .htaccess file with "allow from all" in myfiles.

So why is it working for common.models? There is no .htaccess file in the models folder.

Hi Softarc,

Yes I saw the .htaccess in the Yii folder. And index.php can still access files in Yii by using:

require_once('common' . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'Yii' . DIRECTORY_SEPARATOR . 'yii.php');

But that is for a single file.

I want to be able to access all files in common.myfiles.* so that I can store all my shared code and views there. I don’t want to require_once() all the files individually.

I’m not sure what you mean by “files”.

Do you refer to some image files or css/javascript files that should be directly accessed by the web client?

Hi Softarc

Yes, I have just read a wiki that sort of goes into the same direction as your question.

It looks as if my problem pertains to the KIND of file I want to access.

I have lots of css, layouts, views and javascript that I want to use in both frontend and backend.

So I want to put them under common/myfiles/css and common/myfiles/views, etc.

But I cannot access them unless I put a .htaccess with “allow from all” in the myfiles folder - which I don’t want to do because I have read:

[i]"Deny from all" in a .htaccess file, residing in a directory would deny access to that directory’s contents.

But it does not prevent a PHP script on the server from accessing that content through

include() and require(), as those requests go through the file system, not through the Web server.[/i]

So this means I should be able to access common/myfiles/* even without "allow from all".

But how to do it? I read that "import" works on classes - so probably not on css and views.

CSS files, javascript files and image files are requested by the web server directly. They have to be under the public directory. But the layouts and views are not.

There are many CSS/scripts/images bundled with Yii, and they are under the protected directory. In order to allow the web server to access them, Yii will "publish" them under the "assets" folder using CAssetManager. And the "common" directory of YiiBoilerplate is assumed to be a protected directory.

So, what you want to do will be …

  1. Store CSS/scripts/images under your "common.myfiles" directory. And publish them under "backend.www.assets" and "frontend.www.assets".

  2. Store CSS/scripts/images under your "common.myfiles" directory. And create symbolic links in "backend.www" and "frontend.www".

OK cool.

But how do I access the layouts and views in the common directory?

IMO, layouts and views have absolutely no place in ‘common’.

Keep models, components, extensions, widgets, etc. in common - if they are common, that is.

OK thanks guys.

I have the same problem and have been wrestling for weeks now.

I do have backend where Admins logs in and Posts some Text accompanied by images usong redactorjs. Well they work fine with backend. I’m now struggling on how non-registered users who cannot access backend but front end will access the images. They can see Text since it is in the database but not images which are under backend/www/uploads.

Any idea on how to resolve such problem? I want to display images as well from front end that are stored in backend!



Hi Stefano,

There seems to be 2 easy solutions.

  1. Save images in the front end when you are in the back end.

If the both of the ends are the virtual hosts of a single server, and if the server configuration is under your control, then you can create a symbolic link to a front end directory in the back end.

(I mean, linking "/backend/www/upload" to "/frontend/www/updload")

  1. Load images in the back end when you are in the front end.

You should be able to access the image files in the back end by specifying the full url of them even when you are in the front end.