Direct doesn't use any third-party library.
No configuration needed relative to the server. Direct uses relative paths.
So you just have to upload the files of the framework on your server, and start developing.
The ready-to-use files for your new project. Get the last version on GitHub.
https://github.com/flavienbwk/directframework
This repository contains the files of this website, built with Direct, so you can have examples of how to use Direct.
https://github.com/flavienbwk/directframework/tree/documentation-example
Direct uses the Model-View-Controller architecture to facilitate the understanding of your code by another developer, to organize that code and to make it reliable.
Model | A php class which will proceed to the computation (calculus, functions etc...). This is the brain part. |
---|---|
View | A php file which will include all the HTML of your page, calling the model class functions to render the informations you want. |
Controller | Used to include your models and views. This is this file which will be called by the Router so your view can be shown to the user. |
These three components have their own repositories at the root of the project. Here's how it is organized and the nomenclature to respect.
./Components [This directory contains the Direct classes, traduction files and assets] ./Controller ./Index indexController.php [Compulsory file] whatyouwantController.php ./Model ./Index indexModel.php whatyouwantModel.php ./View ./Index indexView.php whatyouwantView.php .htaccess
Inside Controller/
, Model/
and View/
, you see there's an Index/
folder.
This Index folder is compulsory. It is called when normally calling your index.php root file.
Controller/Index/indexController.php
will be called. So make sure it is always existent.
You have to respect the following nomenclatures to create a new php page (here, called "pagenameyouwant") :
Views | Inside View/WhatYouWant-Folder/pagenameyouwantView.php |
---|---|
Models | Inside Model/WhatYouWant-Folder/pagenameyouwantModel.php |
Controllers | Inside Controller/WhatYouWant-Folder/pagenameyouwantController.php |
To have a more organized code, for each view, you have to create a corresponding controler and model file as shown just up. But this is facultative.
What do we want ?
We want to access the following URL where we would like to display our articles :
What do we want ?
We want the controler to load our models and our views. For example, we will load our navbar and footer in addition to our articles page.
We have then to include these models and views in the articles controler ./Controller/Forum/articlesController.php.
<?php
/*
* CONTROLER FILE.
* Controler/Forum/articlesControler.php
*/
/*
* The two following lines are really important.
* Make sure you have inclued them.
*/
/*
* The following require() is useless since beta-0.1 as Autoloader automatically loads the Page class :
* require(dirname(__FILE__)."/../../Components/Page.class.php");
*/
$Page = new Page();
// ========================================
/*
* Models
* Models are facultative files. For example, if you
* just have to display a view, you don't necessarily
* have to use a model.
*/
// Calling a model, a view or any file must take the following syntax.
// "require($Page->renderURI("path_to_the_file"));"
require($Page->renderURI("Model/Forum/headerModel.php")); // Including the header model.
$HeaderModel = new headerModel();
require($Page->renderURI("Model/Forum/articlesModel.php")); // Including the article model.
$IndexModel = new indexModel();
require($Page->renderURI("Model/Forum/footerModel.php")); // Including the footer model.
$FooterModel = new footerModel();
// ========================================
/*
* Views
* Including the views to display.
*/
require($Page->renderURI("View/Forum/headerView.php")); // View of the navbar and header infos.
require($Page->renderURI("View/Forum/articlesView.php")); // View of the articles.
require($Page->renderURI("View/Forum/footerView.php")); // View of the footer.
// ========================================