How to check an Ajax request in cakephp?

  • You need to enable the RequestHandler component

var $components = array('RequestHandler');

  • Then you check if its an ajax request in your controllers with:


You can find more information about theĀ RequestHandler component here


Depends on the version of cake.





detect if the current page is the homepage with CakePhp

Simply you can try this:

if ($this->request->here == '/') {
       // some code

Also it is good to read this part of documentation:

    $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.