Drupal has a function called “drupal_is_front_page“. Does YII have something similar to deal with navigation in this way?
Drupal has a function called drupal_is_front_page . Does YII have something similar to deal
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Unfortunately not. And while the information needed to piece this together is available, doing so is really more pain than it should be.
To begin with, the front page is defined by the
CWebApplication::defaultControllerproperty, which can be configured as discussed in the definitive guide. But there’s a big issue here:defaultControllercan in reality be any of the following:sitemodule/sitesite/indexmodule/site/indexIf you have specified the
defaultControlleras #4 (which is the same as #3 if your application does not include any modules) then everything is easy:The problem is that if
defaultControlleris specified as #1 or #2 then you have to examine a lot of the runtime information to convert it to form #3 or #4 (as appropriate) so that you can then run the equality check.Yii of course already includes code that can do this: the
CWebApplication::createControllermethod, which can accept any of the valid formats fordefaultControllerand resolve that to a controller/action pair (where controller is dependent on the module, if applicable). But looking at the source doesn’t make you smile in anticipation.To sum it up: you can either assume that
defaultControllerwill always be fully specified and get the job done with one line of code, or borrow code fromcreateControllerto determine exactly whatdefaultControllerpoints to (and then use the one line of code to check for equality).I do not recommend looking into solutions based on URLs because the whole point of routes is that different URLs can point to the same content — if you go that way, can never be sure that you have the correct result.