Welcome Guest, Not a member yet? Register   Sign In
Controller naming PascalCase
#7

I understand the interest, but I don't think it fits into the core framework because it amounts to quite a bit of extra processing for a very specific niche interest (don't worry, I'm totally picky about my code & names too). The problem is that we need to take a route and match it to an actual filename, and "mycontroller/mymethod" could be millions of different manifestations of "mYcOnTrollEr/MyMEthod" since there's no telling where the words split apart. So the fallback is a filesystem search like "foreach ($files as $name) { if strtolower($name) == strtolower($controller))... }" but that's a filesystem read on every autoroute which is a performance hit.

If you really want it you can extend Router\Router yourself. There relevant code is around line 530:
PHP Code:
    /**
     * Attempts to match a URI path against Controllers and directories
     * found in APPPATH/Controllers, to find a matching route.
     *
     * @param string $uri
     */
    
public function autoRoute(string $uri)
    {
        
$segments explode('/'$uri);

        
$segments $this->validateRequest($segments);

        
// If we don't have any segments left - try the default controller;
        // WARNING: Directories get shifted out of the segments array.
        
if (empty($segments))
        {
            
$this->setDefaultController();
        }
        
// If not empty, then the first segment should be the controller
        
else
        {
            
$this->controller ucfirst(array_shift($segments));
        } 

Notice this last part -------^^^^ that simply sets the controller to "ucfirst() of the first segment".
For kebab-case also notice the Router property translateURIDashes - it swaps dashes for underscores but could also be modified.
Reply


Messages In This Thread
Controller naming PascalCase - by RedskyThirty - 12-12-2019, 12:24 PM
RE: Controller naming PascalCase - by ciadmin - 12-12-2019, 01:53 PM
RE: Controller naming PascalCase - by dave friend - 12-19-2019, 12:02 AM
RE: Controller naming PascalCase - by MGatner - 12-20-2019, 07:32 AM



Theme © iAndrew 2016 - Forum software by © MyBB