/php-mvc

A baby PHP Model-View-Controller framework.

Primary LanguagePHP

Starter PHP MVC Framework

A very basic start to your own PHP MVC framework.

Installation

  1. Clone the repo
  2. Go to the root directory in your browser to see the default view. It will display Home Page.

Getting Started

Create a new file in app/models. Example: Contact.php.

In app/models/Contact.php'...

class Contact
{
    public $title = 'Contact Page';
}

Then in app/controllers/ContactController.php...

class ContactController extends Controller
{
    public function index()
    {
        $contact = $this->model('Contact');

        // Loads 'app/views/pages/contact.php' and passes $title which equals 'Contact Page'.
        $this->view('contact', ['title' => $contact->title]);
    }
}

Finally, the $title variable can be used in our view at app/views/pages/contact.php...

<h1><?php echo $title; ?></h1> // Outputs 'Contact Page'

Contributing

  1. Create a branch from the dev branch
  2. Implement your new feature
  3. Submit a pull request to be merge in the dev branch

Author

  • Lansana Camara