1

I want to change the default route in phalcon, which is an index action of indexcontroller.

My routes.php:

$router = new \Phalcon\Mvc\Router();
//Define a route
$router->add(
    "/",
    array(
        "controller" => "admin", //previously it was "index" 
        "action"     => "index",
    )
);
$router->handle();

Now when I open my site (for example http://localhost/test/) in a browser it gives me error:

IndexController handler class cannot be loaded

#0 [internal function]: Phalcon\Mvc\Dispatcher->_throwDispatchException('IndexController...', 2)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 C:\wamp\www\test\public\index.php(36): Phalcon\Mvc\Application->handle()
#3 {main}

I'm confused why my route is going to indexcontroller even after replacing it in the routes file?

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
Mr. Engineer
  • 3,522
  • 4
  • 17
  • 34

1 Answers1

2

to set your default controller you need to use-

$router->setDefaults(array(
   'controller' => 'admin',
   'action' => 'index'  
));
Fazal Rasel
  • 4,446
  • 2
  • 20
  • 31
  • Wow it's working. You saved my day. But i had never wrote this line in my previous project and it's still working fine. – Mr. Engineer Jan 21 '16 at 15:23