Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Mixing controller methods / views - bad idea?

I thought this worked fine before moving to 1.4, has the logic changed at some point?

Basically if I have a controller "Foo", and a method "bar", accesssible via URL "foo/bar", and I also have pages created in the CMS with the same prefix "foo", for example "foo/cms1", "foo/cms2", should the routeing fail?

I recently moved to PHP 7.2 and the latest version of FUEL CMS with one of the clients' websites and can only access the page that is linked to the controller method, but not the other two pages created in the CMS - those fail with a 404.

If I rename the controller the CMS pages load up fine.

Just want to double check if this is intended, of if I'm just missing something simple :-)

Comments

  • edited January 25

    If anyone stumbles across the same issue, I fixed it by basically renaming the controller, and adding a mapping in fuel/application/config/routes.php:

    $route['foo/bar] = 'new_controller_name/bar';
    

    One downside to this approach is that now the other controller is directly accessible as well if users know the URL. I added this check in the new controller to avoid that:

    class New_controller_name extends MY_Controller
    {
    
        function bar()
        {
            $this->_direct_access_block();
            // ... rest
        }
    
       /**
         * Throws a 404 if the user visits this method from a URL that does NOT start with 'foo/bar'
         */
        private function _direct_access_block()
        {
            $uri_string = $this->uri->uri_string();
            if (!starts_with($uri_string, 'foo/bar')) {
                show_404();
            }
        }
    }
    

    EDIT: This would be nicer with a CI hook!

  • I believe that change happened when FUEL was upgraded to CI 3 and the hook that was being used before to allow both controllers and opt-in controller views work together couldn't work the same anymore due to changes in the booting of the CodeIgniter.php file (been a while so am a little fuzzy on the details).

  • Ahhh gotcha :-) Well at least there's a way around it for now.

Sign In or Register to comment.