aymdev/phunder

Lightweight MVC framework including a router and a templating engine.

Installs: 3

Dependents: 0

Suggesters: 0

Stars: 4

Watchers: 4

Forks: 0

Open Issues: 0

Type:framework

v2.1.0 2018-11-09 11:53 UTC

README

Lightweight MVC framework including a router and a templating engine.

Installation

Clone/download the repo and run composer install. Or in a single command: composer create-project aymdev/phunder

Getting Started

After installing, you can reach the demo page : your_phunder_path/ or your_phunder_path/home.

Architecture

Your PHP classes must be located in the app/ directory and follow the PSR-4 standard.
Config file must be located in the config/ directory and included in public/index.php.
Every Front-End asset file must be located in public/ directory without mandatory structure (see URL management for linking).

MVC

Your controller classes are stored in app/Controller/ by default and must extend Phunder\Core\Controller\Controller.
Your controller related model classes are stored in app/Model/ by default and must extend Phunder\Core\Model\Model.
You can change those paths in config/phunder_config.php but they must have the same structure and classes must have the same name.

When you need data from your model simply call your controller's model method:

self::model()->modelMethod();

If this data is needed in your template, give it a name:

self::model('var_name')->modelMethod();

For any data from somewhere else that you need into a template there is the Controller::set() method:

self::set('var_name', $obj->method());
self::set('key', 'value');

Templates

Phunder uses EKF - Element-Key-Flag as its core templating engine.
Create your templates in app/Templates/ (default location defined in config/phunder_config.php).

To render a template, call your controller's render method with the template path relative to the templates directory:

self::render('home.html');

Take a minute to learn EKF syntax

URL management

Phunder uses PPRR - Pure PHP Regex Router as its core router.
Simply define routes as partial regular expressions (see above link) in public/index.php.

URL are rewritten by the .htaccess file using mod_rewrite. Every request will be sent to public/index.php. Your assets files (stylesheets, scripts, images ...) links must be prefixed with _front/. Example:

<link rel="stylesheet" href="_front/css/styling.css">

Demo

There is a demo route to let you try it. You might be interested in looking at these files :

Phunder/
├── app/
│   ├── Controller/
│   │   └── Home.php
│   ├── Model/
│   │   └── Home.php
│   └── Templates/
│       └── home.html
└── public/
    └── index.php