refactored
This commit is contained in:
parent
53c4e1e618
commit
b933d83595
4 changed files with 11 additions and 5 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
### Front Controller
|
||||
|
||||
A [front controller](http://en.wikipedia.org/wiki/Front_Controller_pattern) is a single point of entry for your application.
|
||||
|
||||
To start, create an empty directory for your project. You also need an entry point where all requests will go to. This means you will have to create an `index.php` file.
|
||||
|
||||
A common way to do this is to just put the `index.php` in the root folder of the projects. This is also how some frameworks do it. Let me explain why you should not do this.
|
||||
|
@ -38,6 +40,4 @@ If there is an error, go back and try to fix it. If you only see a blank page, c
|
|||
|
||||
Now would be a good time to commit your progress. If you are not already using git, set up a repository now. This is not a git tutorial so I won't go over the details. But using version control should be a habit, even if it is just for a tutorial project like this.
|
||||
|
||||
What you have set up now is called a [front controller](http://en.wikipedia.org/wiki/Front_Controller_pattern). All requests are going to the same file that then decides what to do with it. This is a very common software design pattern.
|
||||
|
||||
[next >>](2-composer.md)
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
### Composer
|
||||
|
||||
Just because you are not using a framework does not mean you will have to reinvent the wheel every time you want to do something. For PHP there is a dependency manager called composer that you can use to pull in 3rd party packages for your application.
|
||||
[Composer](https://getcomposer.org/) is a dependency manager for PHP.
|
||||
|
||||
If you don't have composer installed already, head over to the [website](https://getcomposer.org/) and install it. You can find composer packages for your project on [packagist](https://packagist.org/).
|
||||
Just because you are not using a framework does not mean you will have to reinvent the wheel every time you want to do something. With composer you can install 3rd party libraries for your application.
|
||||
|
||||
If you don't have composer installed already, head over to the website and install it. You can find composer packages for your project on [packagist](https://packagist.org/).
|
||||
|
||||
Create a new file in your project root folder called `composer.json`. This is the composer configuration file that will be used to configure your project and it's dependencies. It must be valid json or composer will fail.
|
||||
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
|
||||
### Error Handler
|
||||
|
||||
The first package for the project will be an error handler that will provide you with nice errors. A nice error page with a lot of information for debugging goes a long way during development.
|
||||
An error handler allows you to customize what happens if your code results in an error.
|
||||
|
||||
A nice error page with a lot of information for debugging goes a long way during development. So the first package for your application will take care of that.
|
||||
|
||||
I like [filp/whoops](https://github.com/filp/whoops), so I will show how you can install that package for your project. If you prefer another package, feel free to install that one. This is the beauty of programming without a framework, you have total control over your project.
|
||||
|
||||
|
|
|
@ -2,4 +2,6 @@
|
|||
|
||||
### Controllers
|
||||
|
||||
A quick definition before we start. When I talk about a controller in this tutorial then I am just referring to a class that has handler methods. I am not talking about [MVC (Model-View-Controller)](http://martinfowler.com/eaaCatalog/modelViewController.html) controllers. MVC can't be implemented properly in PHP anyways, at least not in the way it was originally conceived. So forget about MVC and instead let's worry about [separation of concerns](http://en.wikipedia.org/wiki/Separation_of_concerns).
|
||||
|
||||
to be continued...
|
Loading…
Reference in a new issue