Tutorial for set condition at only home page in cakephp
To check the current page is homepage or not in Cakephp we can use $this->request.
The output of $this->request is given bellow:
object(CakeRequest) {
params => array(
'plugin' => null,
'controller' => 'pages',
'action' => 'display',
'named' => array(),
'pass' => array(
(int) 0 => 'home'
)
)
data => array()
query => array()
url => false
base => '/'
webroot => '/'
here => '/'
[protected] _detectors => array(
'get' => array(
To check this is the homepage of cakephp site we catch the url by using “$this->request->here”.
$this->request->here
Which will return the output
/
Now if you want to set some condition which will only effect in cakephp homepage you can apply the bellow condition
//debug($this->request); //Check what actually return the $this->request variable.
if ($this->request->here == '/') {
// your specific code which will only effect in homepage.
}