Answer the question
In order to leave comments, you need to log in
Why do developers so categorically claim that one front controller is better?
So, a quote from the documentation. They approve:
A much better solution is to use a front controller: a single PHP file that handles every request coming into your application.
There are several problems with this approach, including the inflexibility of the URLs (what if you wanted to change blog.php to news.php without breaking all of your links?) and the fact that each file must manually include some set of core files so that security, database connections and the "look" of the site can remain consistent.
Using Apache's mod_rewrite (or equivalent with other web servers), the URLs can easily be cleaned up to be just /, /contact and /blog.
Answer the question
In order to leave comments, you need to log in
With one entry point, you don't have to worry about routing at all. You add a new route to the config and wrap it to the desired controller. Everything. With proper autoloading, you don't have to worry about what classes are needed for this particular controller. When the number of routes approaches a hundred, you begin to understand that this is much easier.
/blog looks nicer than /blog/index.php and hides implementation details + there is also dynamic routing, when you may not know in advance which URL will come, and you will first have to search in the database or somewhere else.
It's easier to do routing on the application side than half on the application side and half on the webserver side.
You won't be able to completely do routing on the web server side if you need complex logic.
Moreover, the server may not have the same web server under which you write the rules: for example, you write under nginx, and the admins suggest using Apache.
As for me, the issue is debatable. Your arguments are valid, but here's what I think.
1. Concerning a statics. If static is really static, then it should be given completely separately. If the engine still participates in it, this is no longer static.
2. Well, the very essence. I don’t know why, but somehow it’s even more aesthetically pleasing and beautiful for me when the project has one entry point, and not several in different places. I agree that initialization can be included in a separate file. But it’s either to start each file by connecting an init file (as for me, aesthetically ugly)), or also remember which file is the entry point and which is not. Nothing to say about relative addressing within the file system.
At one time in my project I used something like this. There is one entry point. The url is passed the module, action and any additional parameters. App is initialized, parses request and passes control to the required class with all other parameters. And it's really cool.
Although CNCs are no longer as relevant as they used to be, with multiple entry points without routing through mod_rewrite
it is difficult to implement links like /news/ofigennaya-novost-s-dlinnym-zagolovkom-v-url
. And even if you pervert, it’s more pleasant to see the previous link in the URL than/news.php/ofigennaya-novost-s-dlinnym-zagolovkom-v-url
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question