We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Landing page controller

When i visit my site it automatically searches for indexController how can i change that? I want it to load welcomeController instead.

edited Mar '14

you can do it in some ways, the simplest is proper configure your router

$router->add("/",array(
    "controller" => "welcome",
    "action"     => "index"
));

or you can

class IndexController extends \Phalcon\Mvc\Controller 
{
    public indexAction()
    {
        $this->dispatcher->forward(array(
            "controller" => "welcome",
            "action"    => "index"
            ));
    }
}


936

I have tried the first option, but it doesn't work. I have used phalcon devl tools to generate project structure and i'm confused where i should put it in.



40.8k
Accepted
answer
edited Mar '14

I don't know what you have, you have to get your router configured, something like this:

$di->set('router', function(){
    $router = new \Phalcon\Mvc\Router();

    $router->removeExtraSlashes(true);
    $router->setDefaultController(’welcome’);
    $router->setDefaultAction(’index’);

    //you can configure your routing like below
    $router->add("/",array(
        "controller" => "welcome",
        "action"     => "index"
    ));

    $router->add("/test",array(
        "controller" => "something",
        "action"     => "happen"
    ));

    return $router;

});


936

Thank you it works now!