Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Non index route fails when moving controller to a sub directory
  • FuelPHP newbie, struggling with putting a controller in a sub directory. Here's my controller thats in app/classes/controller/movie.php
    class Controller_Movie extends Controller
    {
    
     public function action_index()
     {
    
                    $data = false;                
                    return Response::forge(View::forge('movie/index.tpl', $data));
     }
    
     public function action_details()
     {
                    $data = false;
                    return Response::forge(View::forge('movie/details.tpl', $data));
     }
    
    }
    

    and my routes
    'movie'   => 'movie/index',
    'movie/(:num)'   => 'movie/details',
    

    Both the urls below display the correct view and everything is working fine. localhost/movie
    localhost/movie/10 Now my understanding is I can change the name of the class to Controller_Movie_Index and move the controller into app/classes/controller/movie/index.php When I do this, the index action works, but the details action gives me a 404 Can anyone tell me what I'm doing wrong? I've not edited the routes, and I've made sure my movie.php class has gone from the default class location Thanks in advance Nearly forgot to mention, I'm using smarty with the extension .tpl and $data will be populated at some point incase you were wondering!
  • Try public function action_details($id) and 'movie/(:num)' => 'movie/details/$1',
  • Thanks for the suggestion Thomas, I originally started with that in the route/controller but it wasn't working so I took them out to try and get the simple path working first. I spoke to a friend at work today who suggested that my routes should be...
    'movie'   => 'movie/index/index',
    'movie/(:num)'   => 'movie/index/details',
    

    This worked. I believe the movie/index was working not because it was finding the action_index, but because it was defaulting to it. By updating it to movie/index/index it was looking for the action_index in index.php in the movie directory. /movie/details was failing because it was looking for action_index in details.php (which doesn't exist) in the movie folder. That's my understanding of it. Thanks again for your reply

Howdy, Stranger!

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

In this Discussion