Wizard
Wizard

Reputation: 11265

Yii get project root

For example I have Yii project in location /var/www/yii. How to get this path from controller?

What I try Yii::app()->basePath; I get /var/www/yii/module-name.

I need only /var/www/yii. Of course I can modify this URL with str_replace(), but maybe there is a way to get clearly this root?

Upvotes: 1

Views: 372

Answers (3)

MKR
MKR

Reputation: 46

echo Yii::app()->getBasePath();

Upvotes: 0

Ali MasudianPour
Ali MasudianPour

Reputation: 14459

You can get it like below:

echo Yii::getPathOfAlias('webroot');

This will return the result you want:

var/www/yii/

If you want to get your application path, you can:

echo Yii::getPathOfAlias('application');

Upvotes: 2

Alfons
Alfons

Reputation: 531

Is it an option to get the parent directory of the given path using dirname?

http://php.net/manual/en/function.dirname.php

Upvotes: 0

Related Questions