So, my public/index.php file has these codes now,
<?php
error_reporting(E_ALL);
try {
/**
* Read the configuration
*/
$config = include __DIR__ . "/../app/config/config.php";
/**
* Read auto-loader
*/
include __DIR__ . "/../app/config/loader.php";
/**
* Read services
*/
include __DIR__ . "/../app/config/services.php";
/**
* Handle the request
*/
$application = new \Phalcon\Mvc\Application($di);
//trying to display error pages
$di->set('dispatcher', function() {
$eventsManager = new \Phalcon\Events\Manager();
$eventsManager->attach("dispatch:beforeException", function($event, $dispatcher, $exception) {
//Handle 404 exceptions
if ($exception instanceof \Phalcon\Mvc\Dispatcher\Exception) {
$dispatcher->forward(array(
'controller' => 'error',
'action' => 'show404'
));
return false;
}
//Handle other exceptions
$dispatcher->forward(array(
'controller' => 'error',
'action' => 'show503'
));
return false;
});
$dispatcher = new \Phalcon\Mvc\Dispatcher();
//Bind the EventsManager to the dispatcher
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
}, true);
$di->set('router', function() {
require __DIR__ . '/../app/config/routes.php';
return $router;
});
echo $application->handle()->getContent();
} catch (\Exception $e) {
echo $e->getMessage();
}
and my routes.php file has these codes,
<?php
$router = new \Phalcon\Mvc\Router(false);
// default
$router->add("/", array(
'controller' => 'index',
'action' => 'index'
));
//Set 404 paths
$router->notFound(array(
"controller" => "error",
"action" => "show404"
));
//adding accounts routes
$router->add(
"/accounts",
array(
"controller" => "accounts",
"action" => "index",
)
);
$router->add(
"/accounts/login",
array(
"controller" => "accounts",
"action" => "login",
)
);
$router->add(
"/accounts/signup",
array(
"controller" => "accounts",
"action" => "signup",
)
);
$router->add(
"/accounts/forgotpass",
array(
"controller" => "accounts",
"action" => "forgotpass",
)
);
//adding users
$router->add("(/.)", array(
"controller" => "user",
"action" => "profile",
"param" => 1,
));
$router->handle();
return $router;
and when i try to access localhost/accounts/login, it is printing /accounts/login instead of showing me loginaction.