I am a Zend Framework [version 1] developer, now I am trying to learn the Yii Framework.
How do I get the current router in Yii Framework?
For an example URL of http://site.ru/forum/index?var=val
:
Yii::app()->getRequest()->getQueryString()
will return var=val
,
Yii::app()->getRequest()->getPathInfo()
will return forum/index
,
Yii::app()->getRequest()->getBaseUrl()
will return /forum
,
Yii::app()->getRequest()->getUrl()
will return forum/index?var=val
,
Yii::app()->getRequest()->getHostInfo()
will return http://site.ru
,
Yii::app()->getRequest()->getRequestUri()
will return forum/index?var=val
.
In case you were after the route, not path related information: in most view files (and the layout) you can use $this->route
and if you're not in the right context for that to be available view $this
then you can often use Yii::app()->controller->route
.
Both return the current matching route from the url manager. Something like:
site/index
site/error
user/edit
Additionally, to just get the current controller in use you can use $this->id
to return something like site
or user
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With