index.php path

How do I get a path to the main index.php file?


or just simply

Yii::app()->homeUrl <----- that’s the same as writing ‘yoursite/index.php’

Thanks, bu I wanted something slightly diferent.

I am using an elfinder module and I have to specify a path (not URL!) to the folder with photos, which in my case is in And my protected folder is somwhere completly outside of public_html, so I cannnot just specify it as


For now I have written an additional line in index.php:


and I use ROOT_PATH constant later in elfinder module. But sth tells me there is a better way…

This one:

is an url, that can be generated as:


This one:


Is a path, that can be generated as:


Zaccaria, you are right, but only if I have my application folder in


For example, when I have my application folder in




points to that folder above and nothing potins to


I don’t understand, if your application is installed under


and your images are in


, you need the path:


and nothing points to


because maybe this directory doesn’t exists, or, if exists, it has nothing concerning with the application.

If you need the url of something that lies close to protected, you can create a url:


that will generate



What exactly do you need?

assets, themes, images, css folders as well as index.php file are in folder C:/www/mywebapp, so they are accessible via http protocol under http://localhost/mywebapp. But my protected folder, as well as yii framework folder are somewhere outside the C:/www folders so they cannot be requestet via http. Lets say this are C:/dev/yii/framework and C:/dev/mywebapp-protected.

So I can build my path to http://localhost/mywebapp/images/content as


but maybe there is an variable or some other way to point folder which includes index.php file, so I could point to my folder as


Do you know what I mean?

Well, usually protected lies at the same level of assets, css images and so on.

If you moved the protected in another path, the variable Yii::app()->basePath cannot help you. You can use Yii::app()->assetsPath.’/../’ and so on.

As far as I know, CWebApplication (the class of Yii::app()) has no this variable you need. You can extend Yii and add this variable if you need.

I have always been fine with Yii::app()->basePath->’/../’ because I never changed the folder structure generated by Yiic webapp

You can use dirname(Yii::app()->getRequest()->getScriptFile()) to recover the path just you want, but you have to remove the filename of the script. I didn’t find any better method, and Quiang is using it in some source code (like in CThemeManager) but I’m pretty sure we need a more strightfoward method…

Otherwise, I think the best method is to set an alias for recurrent paths in main.php like:

$basePath = dirname(dirname(dirname(FILE)));

Yii::setPathOfAlias(‘images’, $basePath . ‘/images’);

and the use them like: Yii::getPathOfAlias(…)