I have a very simple implementation that follows the docs and some things I've read, but I'm still stuck. Displaying the '/' route works, but the other routes (/login, /masses, /vendors) do not work... I get a 404 for all of them. AJAX routes are also broken, but I'd like to solve the page routes issue first.
Here is the code:
/config/routes.php:
use Phalcon\Mvc\Router;
$router = new Router(false);
$router->removeExtraSlashes(true);
$router->addGet("/", [
'controller' => 'noauth',
'action' => 'home',
]);
$router->addGet("/masses", [
'controller' => 'noauth',
'action' => 'masses',
]);
$router->addGet("/vendors", [
'controller' => 'noauth',
'action' => 'vendors',
]);
$router->addGet("/login", [
'controller' => 'noauth',
'action' => 'login'
]);
return $router;
/app/controllers/NoauthController.php:
use Phalcon\Mvc\Controller;
class NoauthController extends Controller
{
public function initialize() {
$this->view->setTemplateAfter('layout');
}
public function homeAction() {
$this->view->pick("noauth/home");
}
public function loginAction() {
echo "login";
}
public function massesAction() {
echo "masses";
}
public function vendorsAction() {
echo "vendors";
}
}
/public/index.php
use Phalcon\Loader;
use Phalcon\Mvc\View;
use Phalcon\Mvc\Url as UrlProvider;
use Phalcon\Mvc\Application;
use Phalcon\DI\FactoryDefault;
try {
// Register an autoloader
$loader = new Loader();
$loader->registerDirs(array(
'../app/controllers/',
'../app/models/'
))->register();
// Create a DI
$di = new FactoryDefault();
$di->set('router',function() {
require '../app/config/routes.php';
return $router;
});
// Setup the view component
$di->set('view', function(){
$view = new View();
$view->setViewsDir('../app/views/');
return $view;
});
// Setup a base URI so that all generated URIs include the "tutorial" folder
$di->set('url', function(){
$url = new UrlProvider();
$url->setBaseUri('/');
return $url;
});
// Handle the request
$application = new Application($di);
echo $application->handle()->getContent();
} catch(\Exception $e) {
echo "PhalconException: ", $e->getMessage();
}