Question

I'm using FuelPHP to create a simple web app with a photo gallery. All photos must belong to a gallery, and may only belong to one gallery. Given that a photo must exist as a component of a gallery, I want my URL structure to look something like the following:

To index all photos in gallery #4
/admin/galleries/4/photos

To edit photo 17 in gallery 2
/admin/galleries/2/photos/edit/17

...etc. Pretty obvious pattern. I added the following line to my routes.php to kick things off:

admin/galleries/:gid/photos' => array('admin/photos/index')

...but visiting /admin/galleries/4/photos gives me a 404. Thoughts? Is there another routing pattern I should be using?

Was it helpful?

Solution

This is how I would end up writing it:

// To edit photo 17 in gallery 2
'admin/galleries/(\d+)/photos/edit/(\d+)' => 'admin/photos/edit/$1/$2',

// To index all photos in gallery #4
'admin/galleries/(\d+)/photos' => 'admin/photos/index/$1',

That's assuming your controller is look something like this:

class Controller_Photos extends \Controller {
    public function action_index($gallery) {
    }

    public function action_edit($gallery, $photo) {
    }
}

OTHER TIPS

how to create this link? use

\Uri::create

or

Router::get()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top