panique / mini

Just an extremely simple naked PHP application, useful for small projects and quick prototypes. Some might call it a micro framework :)
1.35k stars 479 forks source link

Get current controller or view NAME? #171

Closed wendaliu closed 9 years ago

wendaliu commented 9 years ago

I was wondering if there is already a built in function to get the current controller or current view NAME.I want to get thse so that I can determine in the header template which menu item is active and so I can set it's css to active.

panique commented 9 years ago

HE, no sorry there's nothing like that. But you could build it like this: Create a static method that gives back the controller name, like Helper::getControllerName(), the according class could look like this (quick & dirty code, not tested):

class Helper {

    static function getControllerName()
    {
        // split URL
        $url = trim($_GET['url'], '/');
        $url = filter_var($url, FILTER_SANITIZE_URL);
        $url = explode('/', $url);

        return $url[0];
    }
}

Maybe you could even do this inside the Application class, like Application::getXXX, I'm not sure.

wendaliu commented 9 years ago

Where would I create this class?