Downloading & installing

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.

Download the classic repository.

The ready-to-use files for your new project. Get the last version on GitHub.


https://github.com/flavienbwk/directframework

Download the example repository.

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

Get started!

The structure.

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.

ModelA php class which will proceed to the computation (calculus, functions etc...). This is the brain part.
ViewA php file which will include all the HTML of your page, calling the model class functions to render the informations you want.
ControllerUsed 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.

MVC structure.

    ./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.

When someone arrives on the index of your website, Controller/Index/indexController.php will be called. So make sure it is always existent.

Create a new page

You have to respect the following nomenclatures to create a new php page (here, called "pagenameyouwant") :

ViewsInside
View/WhatYouWant-Folder/pagenameyouwantView.php
ModelsInside
Model/WhatYouWant-Folder/pagenameyouwantModel.php
ControllersInside
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.

Example : create a new page.

What do we want ?

We want to access the following URL where we would like to display our articles :

(https://)example.com/forum/articles
.

  1. Create the folder and file
    ./Controller/Forum/articlesController.php
  2. Create the folder and file
    ./Model/Forum/articlesModel.php
  3. Create the folder and file
    ./View/Forum/articlesView.php
For example here, accessing
(https://)example.com/forum
will make the framework run
(https://)example.com/Controller/Forum/indexController.php

Example : fill the controler (call the views).

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.

  1. Create the header and footer folders and files. For example, the header will require the following files (the model is facultative) :
    • ./Controller/Forum/headerController.php
    • ./Model/Forum/headerModel.php
    • ./View/Forum/headerView.php
  2. 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.

    // ========================================
  3. Well, hmm... That's all! Access
    yourwebsite.com/forum/articles
    .