Search code examples
phpcakephpcakephp-2.4

Cakephp 2.4.5 Default Controller not loading


I am new in cakephp trying to loading default controller as Pages

This is my route :

Router::redirect ('/', array('controller' => 'pages', 'action' => 'display'));

Router::connect('/pages/**', array('controller' => 'pages', 'action' => 'display'));

When I run "http://localhost/project/index.php" then its working fine but try with "http://localhost/project/" its not loading default controller (Pages)

Without htaccess & with htaccess its giving same issue.

This is error:

Controller class ProjectController could not be found.

Error:

The requested address '/project/index.php/project/' was not found on this server.


Solution

  • Its resolved

    Added baseUrl in app controller:

    function beforeRender(){
      $this->set('baseUrl', 'http://'.$_SERVER['SERVER_NAME'].Router::url('/'));
    }
    

    Removed App.baseUrl from Core.php :

    Configure::write('App.baseUrl', env('SCRIPT_NAME'));
    

    now its working fine on: http://localhost/app/