Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Routing with models that solely belong to other models
  • Hello, I'm building a simple web-app for a friend. One of the features is a photo gallery - I have the data structure as a set of galleries, each of which contains a set of photos. A photo may only belong to one gallery - pretty standard stuff. Given that a photo may only exist in the context of a gallery (e.g. you cannot have a photo outside of a gallery), I'd like my URL structure to look something like the following: /admin/galleries/2/photos/create
    /admin/galleries/2/photos/17 ...as opposed to... /admin/photos/create
    /admin/photos/17 ...etc. I'm still pretty new to both FuelPHP and MVC development in general, so I'm not sure if this is a typical use case or not. How would I go about creating this behavior within FuelPHP? Thanks. EDIT: I should add that I've tried editing routes.php, but have been unsuccessful. I've set up something like the following... 'admin/galleries/:gid/photos' => array('admin/photos/index') ...but I get a 404 when attempting to navigate to /admin/galleries/7/photos
  • Assuming admin is a module, and you have a controller in there called photos with has an action_index method,
    'admin/galleries/:gid/photos' => 'admin/photos/index',
    
    should work just fine. Note that this will not match '/admin/galleries/2/photos/17', as you haven't provided a placeholder for the segment '17'. If you want that, use
    'admin/galleries/:gid/photos/(:any)' => 'admin/photos/index/$1',
    
    whatever the contents of $1 is will be passed as the first parameter of your action_index() method.

Howdy, Stranger!

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

In this Discussion