Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routes
  • How can i have a url like [url=http://domain/ajax.json]http://domain/ajax.json[/url] I've tried the following:
     'routes' => array(
      // This is the default route.  We use a "#" here so that we do not have any
      // reserved routes.
      '#'      => 'welcome',
      '404'     => 'welcome/404',
            'ajax.json' => 'welcome/ajax',
     ),
    
    And it works both [url=http://domain/ajax.json]http://domain/ajax.json[/url] and [url=http://domain/ajax]http://domain/ajax[/url]
    Is there any way i could make it work only [url=http://domain/ajax.json]http://domain/ajax.json[/url] and [url=http://domain/ajax]http://domain/ajax[/url] to give a 404 Also one thing that i am really missing is the way Django handles the urls where everything is a regex and you can define exactly what urls you need without any defaults (most love having defaults, but i like more to have control over every bit of my app) What i'm referring to is the ability to define only what urls you need and that is all, for example something like this:
    'routes' => array(
        '/'           => 'welcome/index',
        '/some-page/' => 'welcome/somepage',
        '/ajax.json'  => 'welcome/ajax',
    ),
    

    Also almost the same thing can be done in Kohana:
    Route::set('default', '')
     ->defaults(array(
      'controller' => 'home',
      'action'     => 'index',
     ));
    Route::set('contact', 'contact')
     ->defaults(array(
      'controller' => 'contact',
      'action'     => 'index',
     ));
    

    And now i only have
    http://domain/
    and
    http://domain/contact/ Everything else gives a 404, so no default http://domain/contact/index only http://domain/contact/ this will work. I really like having controls of the URL's. This way you can control exactly how your URL's are, if they have trailing / or not, what suffix you want them to have, etc. Can this be done in FuelPHP? Is it planned? as i see that it's still in beta but i really like it so far and would want to use it in a project as soon as i can figure it out how i could do this little things like routes and also as soon as we get some docs and examples about how to use the database, and ActiveRecord package.
    Sorry for the long post and questions but i'm really excited about this PHP Framework and i am looking forward in using it in future projects, i just hope there is a way to do things the way i like to do them. Great work so far.
  • Just add a route to 404 from "(:any)" last and anything that wasn't added before it will match the :any route and be routed to the 404.
    '(:any)' => 'welcome/404'
    
  • Great. Works like a charm. Thank you.
    Now i'll just need to wait for docs/examples about how to use Database/ActiveRecord and i'll start using it. One more thing, if i use the catchall method with (:any) does it make sense to keep the '404' => 'welcome/404', route? I've removed it and seems to be working fine.

Howdy, Stranger!

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

In this Discussion