I have been asked to build a PHP application that inserts data into a database and then allows users to run reports on the database.
I have a couple of years of experience of developing in PHP a couple of years ago, but am stuck.
I have read articles about MVC, frameworks, etc… and it all seems to have changed ๐
What is the best method to use? I feel like iv been stuck in a time warp and have now come to back to PHP and it has totally changed. Im questioning everything I knew ๐ I dont even know what directory structure to use to lay the applicaion out ๐
I hope someone can help and offer some advice on how to lay applications out what Design principle to use etc…
Please help im totally lost ๐
Edit: I would prefer not to have to learn a framework, but rather learn how to build an application. ๐
I like your thinking. I had a look at CodeIgniter, Cake and the other frameworks and whilst they were good I decided to write my own. I learnt a ton. The first revision of my framework wasn’t that great but I have two sites running on that without issues. The second edition of it might not be as mature as Cake etc but it makes building PHP apps a breeze and the key thing for me is: I know what every line of code does and it’s super-quick to change and debug.
I think the first thing to do is to think about how you are going to break the app into layers, obvious candidates are:
So taking those elements, you have a basic directory structure:
index.php is my Front Controller. And I put ORM stuff and other helper classes for doing generic work like processing forms and stuff into the /includes directory. Obviously /css and /js houses your static javascript and CSS files.
The Front Controller works in that you have URLs that specify which controller to create – something like: http://www.domain.com/product/1/hello-world. Where product is the name of a class (I call my controllers Controller) – so here my front controller would read the product part of the URL and create an instance of ProductController.
The controllers act upon the rest of the URL that they are given. So ProductController gets params of 1 and hello-world. 1 could be the index of a product to load and display. hello-world is just SEO text to ignore. You could also specify functions to call, so http://www.domain.com/product/list – this time you create a ProductController and call the list function.
There’s different ways to structure a MVC app and forums are full of arguments about it – what I’ve put above my or may not be true MVC but the main goal is to get good abstraction into your app.
I’d recommend checking out Smarty for your View layer. It’s a stable library and provides HTML caching as well.