How to detect if the current page is the homepage with CakePhp?
cakephp, cakephp-2.0, php
Solution
Simply you can try this:
if ($this->request->here == '/') {
// some code
}
Also it is good to read this part of documentation:
You can use CakeRequest to introspect a variety of things about the request. Beyond the detectors, you can also find out other information from various properties and methods.
$this->request->webroot contains the webroot directory.
$this->request->base contains the base path.
$this->request->here contains the full address to the current request
$this->request->query contains the query string parameters.
Problem
How can I detect if the user is on the homepage of my website with CakePhp? May I use `$this->webroot`? The goal is to do something only if the current page is the homepage.