GithubHelp home page GithubHelp logo

chopin's Introduction

mvcblog

A Simple Model-View-Controller Blog Example written PHP, for educational purposes. The MVC framework is embedded in the application itself, it is not a separate library, so all the code can be easily explored in order to understand how the action-based MVC works.

Note: This is an educational project. If you are looking for a framework for a professional project, I recommend you to use any other MVC framework (there are many out there!).

The main MVC components are implemented in the following way:

  1. Model. Each domain entity is a class. In addition to domain classes, there are data mappers which are responsible of SQL sentences needed to retrieve and save instances of the domain objects from and into the database. For example Post and PostMapper are domain objects and data mappers, respectively.
  2. View. Views are plain PHP scripts, with the only responsibility of generating the data views and user input.
  3. Controller. Controllers are PHP classes. Every HTTP request is dispatched by one controller. More specifically, by one action inside a controller. Actions are simple methods inside controllers.

In addition to the minimum components, this example contains:

  • A view helper class (ViewManager), which includes a layout system for the views. All your views are embedded inside layouts, which contain all the repetivive HTML (headers, footers, css declarations, etc). You can use more than one layout if you want (in the example, we use two layouts).
  • An simple internationalization helper class (I18n).

Requirements

  1. PHP 5.4.0.
  2. MySQL (tested in 5.5.40).
  3. A PHP-capable HTTP Server (tested in Apache 2).

Database creation script

Connect to MySQL console and paste this script.

create database mvcblog;
use mvcblog;
create table users ( 
    username varchar(255), 
    passwd varchar(255), 
    primary key (username) 
) ENGINE=INNODB DEFAULT CHARACTER SET = utf8;

create table posts ( 
  id int auto_increment, 
  title varchar(255),
  content varchar(255), 
  author varchar(255) not null, 

  primary key (id), 
  foreign key (author) references users(username)
) ENGINE=INNODB DEFAULT CHARACTER SET = utf8;

create table comments (
  id int auto_increment,   
  content varchar(255), 
  author varchar(255) not null, 
  post int not null, 
  
  primary key (id),  
  foreign key (author) references users(username), 
  foreign key (post) references posts(id) on delete cascade
) ENGINE=INNODB DEFAULT CHARACTER SET = utf8;

Create username for the database

Create a username for the database. The connection settings in the PHP code are in /core/PDOConnection.php

grant all privileges on mvcblog.* to mvcuser@localhost identified by "mvcblogpass";

TODO

  • Add a decent CSS.
  • Include the URL rewritting mechanism to get pretty urls.

chopin's People

Contributors

jmmeilan avatar khvilaboa avatar loredocasar avatar yrodrigez avatar

Watchers

 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.