Yii basics

I can’t figure out why this works:




echo "url is ". Yii::app()->request->hostInfo;



And yet this doesn’t work:




echo "url is ". CHttpRequest->hostInfo;



As far as I can tell Yii::app()->request isn’t documented anywhere, I just stumbled across it. When I read the documentation on CHttpRequest it seems like my code should work. hostInfo is a property of CHttpRequest.

Is there something I’m not getting?

You might want to check out: from The Definitive Guide to Yii for info on Yii::app…

This thread on CHttpRequest might also be useful.




echo "url is ". Yii::app()->request->hostInfo;



The code above works because an instance of the web application is created(look at your index.php) and the "hostInfo" property is populated with a value.

The code below seems to be not valid. The property "hostInfo" is declared as private and you can only access it from within the class itself. Plus, if you want to access a property/method from a static context, you use :: instead of ->




echo "url is ". CHttpRequest->hostInfo;