Mr. Engineer
Mr. Engineer

Reputation: 3515

Want to change phalcon default route

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?

Upvotes: 1

Views: 1258

Answers (1)

Fazal Rasel
Fazal Rasel

Reputation: 4526

to set your default controller you need to use-

$router->setDefaults(array(
   'controller' => 'admin',
   'action' => 'index'  
));

Upvotes: 2

Related Questions