New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Routing, 404 and IndexController #446

Closed
tmihalik opened this Issue Feb 27, 2013 · 2 comments

Comments

Projects
None yet
3 participants
@tmihalik
Contributor

tmihalik commented Feb 27, 2013

It seems that when a dot character exist in the url - and we know that it is invalid url - instead of 404 or exception it always loads the IndexController.
I was run into this when my html referenced to favicon.ico, but this file was not yet created, so Phalcon called IndexController twice.

http://localhost/test <- throws exception, it's ok, no TestController exists
http://localhost/te.st <- loads IndexController instead of exception, why?

Full test case below:

public/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
</IfModule>


public/index.php:

<?php   

ini_set('display_errors', 'on');

//Register an autoloader
$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
    '../app/controllers/',
))->register();

//Create a DI
$di = new Phalcon\DI\FactoryDefault();

//Setting up the view component
$di->set('view', function(){
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../app/views/');
    return $view;
});

//Handle the request
$application = new \Phalcon\Mvc\Application();
$application->setDI($di);
echo $application->handle()->getContent();


app/controllers/IndexController.php:

<?php

class IndexController extends \Phalcon\Mvc\Controller
{
    public function indexAction()
    {
        echo "<h1>Hello!</h1>";
    }
}
@lantian

This comment has been minimized.

Show comment
Hide comment
@lantian
Contributor

lantian commented Feb 27, 2013

@ghost

This comment has been minimized.

Show comment
Hide comment
@ghost

ghost Feb 28, 2013

Collaborator

Since none route is matched the router passes empty values to the dispatcher, and the dispatcher is using the default controller/index to address the request. In 1.0.0 you can set what paths must be used if none existing route is matched:

$router->notFound(array('controller' => 'errors', 'action' => 'notfound404'));

@lantian Hey, your CMS looks nice!, let me know when it's ready to post it on our twitter

Collaborator

ghost commented Feb 28, 2013

Since none route is matched the router passes empty values to the dispatcher, and the dispatcher is using the default controller/index to address the request. In 1.0.0 you can set what paths must be used if none existing route is matched:

$router->notFound(array('controller' => 'errors', 'action' => 'notfound404'));

@lantian Hey, your CMS looks nice!, let me know when it's ready to post it on our twitter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment