-
Notifications
You must be signed in to change notification settings - Fork 1
MVC Architecture Overview
YuliangZhou7 edited this page Mar 31, 2018
·
10 revisions
Webroot: /public
Use <?php echo WEBROOT; ?> to retrieve the webroot from within views
Entry point for the whole application: /public/index.php
The index.php file will require all the components from /app/bootstrap.php which will load all necessary libraries and helpers
index.php file will then create a new Router object which will handle all URL rerouting requests, this object is reloaded each time there is a change in URL(see below)
URL rerouting
- url will look similar to: "http://localhost/infs3202project", then any other sections appended form the url request separated by '/'
- "http://localhost/infs3202project/$1/$2/$3"
- $1 = controller (located in /app/controllers)
- $2 = method (function contained in controller object)
- $3 onwards = parameters to method
bootstrap.php
- will load /app/config/config.php which defines all global variables for db connection, and root and url paths
- Autoload classes instantiated (only classes from /app/core)
/controllers
- Must extend Controllers class in /app/libraries
- Should be named with capital for first letter and class name must be same as file name e.g. "Users"
- First entry point for loading a module, controller then loads view and model(if required)
/models
- Should be named with capital for first letter and class name must be same as file name e.g. "UsersModel"
- If model required database connection, create new Database() in constructor and save as property to object
- For queries on db, create method in model, and within that call $this->db->query($sql) then bind any necessary values (sanitizes query) then call resultSet() or single() both of which will execute then return the query. (default fetch mode is object)
/views
- separated into sub folders based on name of controller (must be all lowercase for folder name), this allows for multiple views for a single controller (use different methods to load views)
- To change to a different view/page use URL rerouting add href="/controller/method/params"