Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Application Controller with same name as module
  • Hello everyone,

    I currently manage a relatively large application written in Fuel PHP 1.4. There are several sites that use modules that are shared across these sites.

    I want to create a module called "Page" to be shared across a few different applications. Unfortunately though there is already a controller in our CMS Application called Controller_Page.

    If the Pages module is loaded, it ignores the Controller_Page from the application classes and tries to load a controller from the Page module's class directory and then throws a 404 because there isn't one there.

    Is there a way to make the module cascade, thereby reverting to the application's controller if no controller is present in the module's class directory?


  • HarroHarro
    Accepted Answer
    Your best bet is probably to extend the Router class, and overload the parse_match() method. If it fails to find a controller, it returns NULL.

    It might work already if you change it to

            // this will search in a module if one is detected
            if ($info = static::parse_segments($segments, $namespace, $module))
            {
                $match->controller = $info['controller'];
                $match->action = $info['action'];
                $match->method_params = $info['method_params'];
                return $match;
            }

            // this will repeat the search in app if a module was detected
            elseif ($module and $info = static::parse_segments($segments, $namespace, false))
            {
                $match->controller = $info['controller'];
                $match->action = $info['action'];
                $match->method_params = $info['method_params'];
                return $match;
            }
            else
            {
                return null;
            }

Howdy, Stranger!

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

In this Discussion