Home | Resume | Blog | Interesting Reads | Tutorials | Skills | Personal Projects | Work Projects | Books | Certifications | Connect with me
Published On: Jul 31 2021
Written By: Krishnan Sethuraman
Written By: PHP
Migrating the static pages was not very difficult. If you have experience working with either Laravel or Codeigniter then this would not be difficult.
The main confusion arose when I was creating the controllers and methods. Unlike Codeigniter, Phalcon has automatic route enabled. So the URLs work like a charm without creating any routes.
However you will encounter an obstacle if you want to set up a custom 404 page. With little bit of research I eventually figured out that this was not very difficult.
Phalcon had a
notFound option in routes to set up custom 404 pages. However this
notFound does not work unless the auto route is turned off.
To turn off auto route you need to navigate to
$router = $di->getRouter();
$router = $di->getRouter(false);
Once done you can now add the below code to route.php and have a custom 404 page.
$router->notFound( [ 'controller' => 'error', 'action' => 'notFound', ]);
However the only drawback to this approach is that you will have to create all other routes that you need in
route.php as the auto route is turned off.