PHP Include function giving error

If the includes folder is located in the same folder where the view file is then there is no problem. but if I place the includes folder in the views folder then it gives error even though I add ‘../’

include(../includes/backtotop.shtml) [<a href=‘function.include’>function.include</a>]: failed to open stream: No such file or directory

I’d recommend using Yii’s import method:

http://www.yiiframework.com/doc/api/1.1/YiiBase#import-detail

Called like this:


Yii::import('alias.path.to.file');

<?php Yii::import(‘application.includes.backtotop.shtml’); ?> moving the includes folder in protected folder and using this statement gives no output

<?php Yii::import(‘includes/backtotop.shtml’); ?> this gives error

My mistake, it’s not a class file you’re looking to import.

Try this instead:




include(Yii::getPathOfAlias('application.includes') . '/backtotop.shtml');



I want to have the includes folder inside the views folder or at the root folder where css and javascript folders are also present. How to amend the code for these two cases ?

Just use the appropriate path alias and it should work regardless of its location.

try this


<?php

include(Yii::getPathOfAlias('application.views.includes') . '/filename.php');