TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Each request is a 404 error
  • I have a problem. Yesterday I said that my view was loaded twice when I was using the step to step with XDebug.

    I think I found why, it's because all my requests generates a 404 error.

    Here is my log, si is append for each request.

    2014-03-13 19:50:09 --- CRITICAL: HTTP_Exception_302 [ 302 ]:  ~ SYSPATH\classes\Kohana\HTTP\Exception.php [ 17 ] in C:\wamp\www\site\system\classes\Kohana\HTTP.php:33
    2014-03-13 19:50:09 --- DEBUG: #0 C:\wamp\www\site\system\classes\Kohana\HTTP.php(33): Kohana_HTTP_Exception::factory(302)
    #1 C:\wamp\www\site\application\classes\App.php(498): Kohana_HTTP::redirect('dog/index', 302)
    #2 C:\wamp\www\site\application\classes\App.php(310): App::redirect('dog/index')
    #3 C:\wamp\www\site\application\classes\HTTP\Exception\404.php(12): App::redirect_last_page(NULL, NULL)
    #4 C:\wamp\www\site\system\classes\Kohana\HTTP\Exception.php(17): HTTP_Exception_404->__construct('Unable to find ...', Array, NULL)
    #5 C:\wamp\www\site\system\classes\Kohana\Request.php(975): Kohana_HTTP_Exception::factory(404, 'Unable to find ...', Array)
    #6 C:\wamp\www\site\index.php(118): Kohana_Request->execute()
    #7 {main} in C:\wamp\www\site\system\classes\Kohana\HTTP.php:33
    2014-03-13 19:50:09 --- CRITICAL: HTTP_Exception_302 [ 302 ]:  ~ SYSPATH\classes\Kohana\HTTP\Exception.php [ 17 ] in C:\wamp\www\site\system\classes\Kohana\HTTP.php:33
    2014-03-13 19:50:09 --- DEBUG: #0 C:\wamp\www\site\system\classes\Kohana\HTTP.php(33): Kohana_HTTP_Exception::factory(302)
    #1 C:\wamp\www\site\application\classes\App.php(498): Kohana_HTTP::redirect('dog/index', 302)
    #2 C:\wamp\www\site\application\classes\App.php(310): App::redirect('dog/index')
    #3 C:\wamp\www\site\application\classes\HTTP\Exception\404.php(12): App::redirect_last_page(NULL, NULL)
    #4 C:\wamp\www\site\system\classes\Kohana\HTTP\Exception.php(17): HTTP_Exception_404->__construct('Unable to find ...', Array, NULL)
    #5 C:\wamp\www\site\system\classes\Kohana\Request.php(975): Kohana_HTTP_Exception::factory(404, 'Unable to find ...', Array)
    #6 C:\wamp\www\site\index.php(118): Kohana_Request->execute()
    #7 {main} in C:\wamp\www\site\system\classes\Kohana\HTTP.php:33
    

    Twice the same error. But my view is correctly loaded and everything works. I tried to disable all my modules, it's the same. Then I disabled my controller behaviour, still the same. I don't know where it's from, do you have any idea why?

    Bootstrap:

    /**
     * *********************************************************************************************
     * ************************************** Dogs *************************************************
     * *********************************************************************************************
     */
    
    /**
     * Dogs front page.
     */
    Route::set('chiens', 'chiens')
        ->defaults(array(
            'controller' => 'dog',
            'action' => 'index'
        ));
    Route::set('dogs', 'dogs')
        ->defaults(array(
            'controller' => 'dog',
            'action' => 'index'
        ));
    
    /**
     * *********************************************************************************************
     * ************************************** Cats *************************************************
     * *********************************************************************************************
     */
    
    /**
     * Dogs front page.
     */
    Route::set('chats', 'chats')
        ->defaults(array(
            'controller' => 'cat',
            'action' => 'index'
        ));
    Route::set('cats', 'cats')
        ->defaults(array(
            'controller' => 'cat',
            'action' => 'index'
        ));
    
    /**
     * *********************************************************************************************
     * ************************************** Default **********************************************
     * *********************************************************************************************
     */
    
    /**
     * Set the routes. Each route must have a minimum of a name, a URI and a set of
     * defaults for the URI.
     */
    Route::set('default', '((/(/)))')
        ->defaults(array(
            'controller' => App::config('routes.default_controller'),
            'action'     => App::config('routes.default_action'),
        ));
    
  • please, dont create over 9000 discussions - use one and wrap code in pre tag

  • First, you have problems with your routes. Actually none of your routes are matching. This is why you are always getting 404. Here's the manual :)

    http://kohanaframework.org/3.3/guide/kohana/routing

    The log shows that inside the HTTP_Exception_404 constructor, you are redirecting via App::redirect_last_page which calls App::redirect which calls Kohana_HTTP::redirect('dog/index', 302).

    Now, this is very strange :))

    Kohana_HTTP is an abstract class and should not be used directly. What is strange is that how you are making PHP call an abstract class' method directly? On which PHP version you are? Is there any intermediate code or stack trace that is not logged?

    We usually redirect from Controller::redirect() inside our controller actions. Outside of your controller you should create an HTTP_Exception_302, change the URL via the location method and then throw it.

    Happy coding!

  • I looked about how make it readable. Didn't know about "pre" and found nothing about it on the forum, so, yeah, that was ugly.

    What I don't understand is ... If no route is matching, why the good controller/view is it called? Sounds weird.

    I used old code from the 3.1 version and I'm in 3.3 now, maybe I did wrong at the time or it worked differently.

    Anyway, I'l take a look to that, because yes, I'm using an abstrat class method.

  • By the way, Controller::redirect() calls directly Kohana_HTTP::redirect(), so I just missed one step and it actually changed nothing.

    I still get the same error, with one step more. And I still don't understand why my code works since it cannot resolve the route... The debug mode is useless and doesn't stop when the breakpoint is reached.

    i have no clue about what's going on. Is there any way to debug properly?

  • Well, for your routes, you can debug/test them properly with this devtools module, I use this fork:

    https://github.com/michal-m/kohana-modules-devtools

    None of your routes are matching for the "dog/index" url, except maybe the default route at the end.

    Please use the devtools to see the route that is matching for the url your trying to call initially, and then the route that is matching for your custom 404 redirection url.

    Regarding Kohana_HTTP::redirect()... I never knew we can call a static method of an abstract class, directly!... sorry, my bad.

  • "I looked about how make it readable" http://forum.kohanaframework.org/discussion/501/howto-use-the-forum-ask-for-help-vfaqs-dos-and-donts/p1 "pre tag" it's html tag for wrap code. < pre >...code...< /pre >

    Other toolbar https://github.com/biakaveron/debug-toolbar

    Please, write easier - current posts are difficult to understanding :( Describe the task in solving that problem - maybe it is implemented differently

    publish the code (or part) on githab or a similar service - impossible find concrete bug without analyzing code

  • None of your routes are matching for the "dog/index" url, except maybe the default route at the end.

    It's what I expect to. My custom route is with dogs or dogs/index

    dog/index should be matched by the default route.

    Why the fact to match the default route generate a log error? It's confusing. I'll push my code on github soon, I don't like to bother other people with my code if I can fix it by myself, I'll give a try to your debug tools before too.

    Thanks.

  • Route::set('dogs', 'dogs')
        ->defaults(array(
            'controller' => 'dog',
            'action' => 'index'
        ));
    

    This route will not match dogs/index.

  • Ah? Because it does works. And if I remove it, it doesn't. So I guess that works...

  • @vadorequest wrap string of code in "`" or tag "code".

    route 'dogs' match only /dogs and /dogs/ replace as Route::set('dogs', 'dogs(/<action>)') for match dogs/index

  • Hum... yeah, I'll try that, I think you're right.

    Thanks.

  • Devtools is great, thanks. Really useful module. No doc about debug-toolbar, I'll take a look.

  • Here is my git project.

    https://github.com/Vadorequest/kohana-3.3.1/tree/master/kohana

    Url is kohana/ Still need to create the DB (kohana) and read the readme to see the feature changes I did, create the log table (or disable the log feature).

    What I get on my log now is different:

    2014-03-14 17:55:21 --- CRITICAL: ErrorException [ 1 ]: Maximum function nesting level of '100' reached, aborting! ~ SYSPATH\classes\Kohana\Arr.php [ 91 ] in file:line
    2014-03-14 17:55:21 --- DEBUG: #0 [internal function]: Kohana_Core::shutdown_handler()
    #1 {main} in file:line
    2014-03-14 17:55:22 --- CRITICAL: ErrorException [ 1 ]: Maximum function nesting level of '100' reached, aborting! ~ SYSPATH\classes\Kohana\Arr.php [ 91 ] in file:line
    2014-03-14 17:55:22 --- DEBUG: #0 [internal function]: Kohana_Core::shutdown_handler()
    #1 {main} in file:line

    Thanks for your help.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion