Coder Social home page Coder Social logo

mvc's Introduction

Building MVC framework with PHP

Project structure:


  d-App
    d-Controllers
      d-Admin
    d-Views
    d-Models
  d-Core
    l-Dispatcher 
    l-Controller
    l-View
  d-public
    .htaccess
    l-index.php
   d-vendor
   

Routing: how URLs are processed in n MVC framework

  1. Create a central entry point to the framework: the front controller
  2. Configure the web server to have pretty URLs
  3. Get the controller and action from a URL with a variable structure, using regular expression

Controllers and actions

  1. Dispatch the route: create the controller object and run the action method
  2. Load classes automatically: add namespaces and an autoload function. (with composer)
  3. Remove query string variables from the URL before matching to a route
  4. Action filters: call a method before and after every action in a controller

Views

  1. Display a view: create a class to render views and use it in a controller
  2. Make views easier to create and maintain: add a template engine (with Twig)
  3. Remove repetition in the view templates: add a base template to inherit from

Models

  1. Add a model, get data from the database and display it in a view
  2. Optimise the database connection: connect only on demand and reuse it

Manage code using Composer

  1. Install the template engine library Twig using Composer
  2. Include all package classes automatically using the Composer autoloader
  3. Replace the autoload function with the Composer autoloader

Error handling

  1. Put application configuration settings in a separate file
  2. Handle errors: convert errors to exceptions and add an exception handler
  3. Handle errors: convert errors to exceptions and add an exception handler
  4. Categorise different types of error using HTTP status codes
  5. Add views to make error pages look nicer for users

mvc's People

Contributors

lukas713 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.