Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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"
            ));
    }
}


637

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.



29.4k
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;

});


637

Thank you it works now!