PHP todoApp - Live Preview - Heroku
PHP MVC Base - forked from jimmiw/php-mvc-base
Main structure of php project. Folders / files:
- app
- controllers
- models
- views
- config
- lib
- base
- web
The web/index.php is the heart of the system. This means that your web applications root folder is the “web” folder.
All requests go through this file and it decides how the routing of the app should be. You can add additional hooks in this file to add certain routes.
The root of the project holds a few directories: /app This is the folder where your magic will happen. Use the views, controllers and models folder for your app code. /config this folder holds a few configuration files. Currently only the connection to the database. /lib This is where you should put external libraries and other external files. /lib/base The library files. Don’t change these :) /web This folder holds files that are to be “downloaded” from your app. Stylesheets, javascripts and images used. (and more of course)
The system uses a basic MVC structure, with your web app’s files located in the “app” folder.
Your application’s controllers should be defined here.
- All controller names should end with “Controller”. E.g. TestController.
- All controllers should inherit the library’s “Controller” class. However, you should generally just make an ApplicationController, which extends the Controller. Then you can defined beforeFilters etc in that, which will get run at every request.
Models handles database interaction etc.
All models should inherit from the Model class, which provides basic functionality. The Model class handles basic functionality such as:
- Setting up a database connection (using PDO)
- fetchOne(ID)
- save(array) → both update/create
- delete(ID)
Your view files. The structure is made so that having a controller named TestController, it looks in the app/views/test/ folder for it’s view files.
- All view files end with .phtml Having an action in the TestController called index, the view file app/views/test/index.phtml will be rendered as default.
Your routes around the system needs to be defined here. A route consists of the URL you want to call + the controller#action you want it to hit.
An example is:
$routes = array(
'/test' => 'test#index' // this will hit the TestController’s indexAction method.
);
A general error handling has been added.
If a route doesn’t exist, then the error controller is hit. If some other exception was thrown, the error controller is hit. As default, the error controller just shows the exception occured, so remember to style the error controller’s view file (app/views/error/error.phtml)
- PHP Developers Guide.
- .gitignore file configuration. See Official Docs.
- Git branches. See Official Docs.