Check For Home Url

How to check if url request is the home url in any case?

( or

I want to load a library only on home url but not into default Controller/Action.

The loading must become inside of default layout

The only way I found is to set a property in default controller and set to true when default action invoked, and check in layout if it is true.

Any other well-structured approach?


In layout, you can echo $this->id and $this->action->id and see what they return :)

Also you can compare them with defaultController and defaultAction:

For defalut controller ok. According tou your post I found the Yii::app()->defaultController (returns a string)

but what about default action of default controller? the second link you posted is about an instance of controller (and not of no-nessessary implemented controller)

A little bit help please? :)

There are two posts. See the first one first :)

To get the default action, you should use


You can use the current controller because you’re only going to compare action ID’s if you’ve already confirmed that the controller ID is correct.

$isDefault = $this->id === Yii::app()->defaultController 

          && $this->action->id === $this->defaultAction;

For answer your question "Any other well-structured approach?", yes, set properties in the controller and check in the layout is a standard procedure.

You better set this properties in a masterclass for controller (like protected/components/controller) in order to be sure that the properties will exist in all controllers that uses the layout.

Thanks all of you :)

This extension might come in handy as well.