I'm fine with the idea of a router simply being a router; I really take exception to yet more PHP examples illustrating bad coding habits being on the web though.
include("views/articles.php");
to
return view ('articles');
would be better...
The actual library code is just the 91 line file in the root directory. I don't understand why people are being so negative about 91 lines of code. It's very simple and most of it is quite well written.
How is this project 'misguided', just from face value?
Right - and examples are meant to illustrate how to best use a library.
How you write your handlers and display your views is completely up to you. Why should a simple router dictate how you write the rest of your code?
I agree that it could negatively influence code that more novice programmers might write with it. They should replace the code inside the page handlers with a comment indicating that the user should render output there.
There's always a benefit to not copying and pasting code, which is what writing an include in each of your handlers boils down to.
It boils down to sloppy thinking; your objects should be well defined enough that you're not having to include extra pieces of code in the middle of execution.
You could argue code reuse - but why isn't that code either part of the object in the first place, or an object in its own right?
If you know some examples of elegant code written with includes scattered throughout it, conditionally or otherwise, I'd love to see it.
I will make exceptions for some parts of page rendering; it can sometimes be a good idea to put page elements into their own files and pull together when necessary. But for including code? No. Just no.
Edit: I took exception in this case, as it's non-obvious what happens once the view file has been included, not to mention the lack of a base example handler class implies and encourages people to write code like this.
I confess that I stopped digging further after I saw files being included in methods, absolutely one of the biggest sins in PHP:
https://github.com/anandkunal/ToroPHP/blob/master/examples/b...
https://github.com/anandkunal/ToroPHP/blob/master/examples/b...