Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Problems with second controller file in Module
  • Update: Problem solved!


    Hi guys, i'm working on a small script in my free time. Currently i complete the Admin Interface...
    Now i have some problems to execute a second file.
    If i use the following url, i can see the site:
    users/admin/users/settings
    

    but if i run the following, i see only my definied 404 site :(
    admin/users/settings
    
    The files are placed in the following directory:
    modules/users/classes/controller/admin
    
    In this directory are two files: * users.php * settings.php
    users.php
    <?php
    
    namespace Users;
    
    class Controller_Admin_Users extends \Controller_Admin 
    {
    
    settings.php
    <?php
    
    namespace Users;
    
    class Controller_Admin_Settings extends \Controller_Admin 
    {
    
    The config/routes.php is the following
    <?php
    return array(
     '_root_'  => 'main/index',  // The default route
     '_404_'   => 'main/404',    // The main 404 route
     
     'login'                                         => 'users/login',
            'logout'                                        => 'users/logout',
            'register'                                      => 'users/register',
            'confirm/(:any)'                                => 'users/confirm/$1',
            'admin'                                         => 'main/admin/main',
            'admin/(:segment)'                              => '$1/admin/$1',
            'admin/(:segment)/(:any)'                       => '$1/admin/$1/$2',
            'admin/(:segment)/(:any)/(:any)'                => '$1/admin/$1/$2/$3',
            'admin/(:segment)/(:any)/(:any)/(:any)'         => '$1/admin/$1/$2/$3/$4'
    );
    
    I'm a bit confused about this, because it should work, the second admin line is for me the same as in the working url.
    Please help me!
    Thanks a lot.
    Regards, Marcus
  • It should match "admin/(:segment)/(:any)". The others are useless, as ":any" will match anything, so all URL's with more then three segments will be matched by this line. I don't see an immediate reason why it shouldn't match that rule. You could add some debugging to Route::_parse_match() to see why it doesn't match.
  • Hi, thanks for the fast answer. I checked the route.php but there is no function "_parse_match()".
    I am using fuelPHP 1.2.1.
    Is this the problem?
  • My bad, I meant "_parse_search". It runs a preg_match() to see if the route matches the URI.
  • Hi, yeah no problem. i found the function now here the result: http://pastebin.com/3zjgtzDV (line 198 ff.)
    As i can see, it returns one times "1" and then it runs again the routing and returns the 404..
    EDIT: I checked also the $result === 1 and it retuns the page.. but don't know why is there a second redirect... I have updated the action_index function with "echo "hello";" but same result... hmm...
  • It indeed looks like it matches the URI correctly. If there is a redirect, and you have logging set to a high enough level, you should see the requested URI in the log.
  • Okay i found the solution..
    Direct access is via: http://tc.local/public/users/admin/settings With routing it will redirected to http://tc.local/public/users/admin/users/settings So i have to add a custom route for this like:
            'admin/(:segment)/settings'                     => '$1/admin/settings',
    
    
    And it works.... HOLY!
    Thanks a lot for your help!
    Is the way now to set the settings.php in a subdirectory "users" to use the default routing,
    or is there also a other solution?
    Regards, Marcus
  • Ok, so no redirect or other odd request that causes the 404. What can also cause the 404 is if the Request::execute() method can't map it to a controller/method for some reason. So maybe you're next port of call is to debug that, see if it gets there at all, and if so, where it goes wrong. You can use log calls instead of echo's to make sure you've got everything, like this:
    logger('Info', 'DEBUG: we are now here, var = '.$var);
    
  • Thanks Harro for the information :) it was my bad, because i wrote a wrong url ( not using copy&paste; ) for the direct access. Now i moved the settings.php from the "admin" directory to "admin/users".
    Thanks a lot, and here from germany,
    have a nice evening ;)
  • Good you've got it sorted. Good luck with your project.

Howdy, Stranger!

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

In this Discussion