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.

404 page not work

my routes

$router = new Phalcon\Mvc\Router();

$router->add('/login/', array(
    'controller'  => 'user',
    'action'      => 'login'
));

$router->add('/signup/', array(
    'controller'  => 'user',
    'action'      => 'signup'
));

$router->notFound(array(
    'controller'  => 'user',
    'action'      => 'show404'
));

return $router;

my controler

class UserController extends ControllerBase
{

    public function loginAction()
    {

    }


    public function signupAction()
    {

    }


    public function show404Action()
    {
        $this->response->setHeader(404, 'Not Found');
        $this->view->pick('404/404');
    }
}

test

site.com/login/ -> ok

site.com/signup/ -> ok

site.com/test/ -> TestController handler class cannot be loaded <- wtf?

how to make?

HI @stanleer ! Use $router = new Phalcon\Mvc\Router( FALSE ); for disable auto-router ( http://docs.phalconphp.com/en/latest/reference/routing.html#default-behavior )



9.4k

add false not work too

I can't see Routes file and Controller file... anyway i would check the Namespace of the TestController or if test is an action of the IndexController (and this is a default route) you should check the RewriteLog (enabling it in the .htaccess) as in rewriting can happen a lot of problem... (for example: http://forum.phalconphp.com/discussion/1393/indexcontroller-cause-unmanaged-404-error-on-apache-w-mod-rewrit )



9.4k

first post corrected

Oh, sure! Your router contain default routings to :controller and :action parameters. (if you debug it you will find this default routes this in the $router object) try to insert $router->clear(); just before any $router->add...



9.4k
Accepted
answer

solution

routes.php

<?php

$router = new Phalcon\Mvc\Router(false);

// 404 страница
$router->notFound(array(
        'controller'    => 'error',
        'action'                => 'show404'
));

$router->add('/login/', array(
        'controller'    => 'user',
        'action'                => 'login'
));

$router->add('/signup/', array(
        'controller'    => 'user',
        'action'                => 'signup'
));

...

return $router;

ErrorController.php

<?php
use Phalcon\Mvc\View;

class ErrorController extends \Phalcon\Mvc\Controller
{

        public function show404Action()

                $this->view->disableLevel(View::LEVEL_MAIN_LAYOUT);
                $this->response->setStatusCode(404, "Not Found");
        }
}