agentejo / lime

micro php web framework
MIT License
200 stars 22 forks source link

Root OO Class #24

Closed giovannibr closed 7 years ago

giovannibr commented 7 years ago

I'm trying to bind a class as the root route. Something like: "http://mysite.com/" showing the "index" method of my class "Pages". And not "http://mysite.com/pages".

I've tried using the second param of bindClass method (alias) with an empty string, like: $app->bindClass("Pages", "");

But it fails using the "alias" param when an empty string returns false for a soft test at line 778: $clean = $alias ? $alias : trim(strtolower(str_replace("\\", "/", $class)), "\\");

So, I could fix this changing the bindClass method. The changed lines are 778 and 780:

778 - $clean = $alias !== false ? $alias : trim(strtolower(str_replace("\\", "/", $class)), "\\");
779 - 
780 - $this->bind(empty($clean) ? '/*' : '/'.$clean.'/*', function() use($self, $class, $clean) {

Maybe you could update it too ;)

CyDoor commented 7 years ago

To bind a class directly to root you have to bind it like that: $app->bindClass('Pages','/');

PHP handles the backslash as root space. You should change your code again, here is no update necessary. if you dont believe, take a look at similar Frameworks like slim/silex every where you see '/' as root and if you look at your domain there is an "/" after the domain :-)

aheinze commented 7 years ago

@CyDoor thanks for helping out!