From ece781990d952be64d9cf9796848ee294342dda2 Mon Sep 17 00:00:00 2001 From: Patrick Date: Sat, 20 Sep 2014 19:56:51 +0200 Subject: [PATCH] Changed former controller part --- 6-dispatching-to-a-class.md | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 6-dispatching-to-a-class.md diff --git a/6-dispatching-to-a-class.md b/6-dispatching-to-a-class.md new file mode 100644 index 0000000..31f2fbe --- /dev/null +++ b/6-dispatching-to-a-class.md @@ -0,0 +1,57 @@ +[<< previous](5-router.md) | [next >>](7-inversion-of-control.md) + +### Dispatching to a Class + +In this tutorial we won't implement [MVC (Model-View-Controller)](http://martinfowler.com/eaaCatalog/modelViewController.html). MVC can't be implemented properly in PHP anyway, 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). + +Instead of just calling everything a controller, let's give our names descriptive names that describe what the class actually does. In this case, we will just display content, so a fitting name would be `Presenter`. If the class does something else, we will name it accordingly. + +Create a new folder inside the `src/` folder with the name `HelloWorld`. This will be where all your hello world related code will end up in. In there, create `HelloWorldPresenter.php`. + +```php +$method($vars); + break; +``` + +So instead of just calling a method you are now instantiating an object and then calling the method on it. + +Now if you visit `http://localhost:8000/hello-world` everything should work. If not, go back and debug. And of course don't forget to commit your changes. + +[<< previous](5-router.md) | [next >>](7-inversion-of-control.md) \ No newline at end of file