DOCUMENTATION PAGE

Introduction

Dedelang is an application development framework to help the developer who need simple and secure to create the web applications. The purpose of this framework is to enable you to develop web applications much faster than your write the code from the scratch. This framework also has embedded web application firewall (WAF) to protect your applications from suspicious activity.

Installation Guide

Initial Command your need write to start project:

  • 1. Changes directory into your project directory.

    Example command:

    C:\xampp\htdocs>cd blog
  • 2.Run the initial zeref command

    Example command:

    C:\xampp\htdocs\blog>php zeref start-project
  • 3. To test the project your can run command below or your can access through HTDOCS in xampp

    Example command:

    C:\xampp\htdocs\blog>php -S localhost:8080

    Access through localhost:

    Click this link http://localhost/blog

Configuration

All of configuration for the Dedelang framework done in file . That config file can be seen in config directory. For start the new project you just need to define database connectivity and the base URL in config file.

  • Example configuration file .env.
      DB_CONNECTION=mysql
      DB_HOST=localhost
      DB_PORT=3306
      DB_DATABASE=blog
      DB_USERNAME=root
      DB_PASSWORD=password
    
      INPUT_SECURITY=OFF
      NAME_FIELD_SECURITY=OFF
      KEY_SECRET=Y0U_S3cr3T_h3R3
    
      BASE_URL=http://localhost/blog
    
                  

Routing

Routing libraries in the Dedelang to make URI of application to become simple and easy to understand. All routing process stored in file App/Path/web.php. Each of route set in file App/Path/web.php assign for single URL in the application.

  • Process to set URL routing in file App/Path/web.php:

    For example, you want to access the URL http://your-app-name/user in your browser, so you need to define route like this:

                      

    <?php
    use Dedelang\Engine\Route;

    Route::set('user','User@index');

CSRF protection

CSRF protect is processed to avoid the end user to execute unwanted actions on a web application.

In Dedelang framework every post method needs value CSRF token to execute actions on the web application.

  • Example form with CSRF token
                        

    <form action="register" method="POST">

    First name:

    <input type="text" name="firstname">

    Last name:

    <input type="text" name="lastname">

    <?php Html::csrf(); ?>

    <input type="submit" value="Submit">

    </form>

Controllers

The controllers are process to hander the all logic process into a single class. Controllers are stored in the App/Controllers directory.

  • Example Controllers Class:
    
      

    <?php

    namespace Controllers;

    use Dedelang\View\View;

    use Models\WelcomeModel;

    class WelcomeController{

    public function index(){

    View::body('Welcome');

    }

    }

    ?>

    // Note: In controllers’ class all the function much be in static function.

Models

The query data from database occur in models’ class. All the model file stored in App/Models directory.

  • Example Models Class:
    
                            

    <?php

    namespace Models;

    use Dedelang\Engine\DB\Query;

    use Dedelang\Http\Request;

    use Dedelang\Engine\Validate;

    class UserModel{

    public function get(){

    $data = Query::table('users')

    ->select('*')

    ->getOne();

    return $data;

    }

    ?>

Query statement

Query statement is process to rieteric, save, delete and update data from the database.

  • Example get data in single row:
    
                              

    public static function get(){

    $data = Query::table('users')

    ->select('*')

    ->getOne();

    return $data;

    }

  • Example get data in all rows:
    
                              

    public static function getAll(){

    $data = Query::table('users')

    ->select('*')

    ->getAll();

    return $data;

    }

  • Example insert data:
    
                              

    public static function insert(){

    Query::table('users')

    ->insert('firstname','lastname','email')

    ->values('Rosmiati','Junaidi','rosmiati_junaidi@gmail.com')

    ->run();

    }

  • Example update data:
    
                              

    public static function update(){

    Query::table('users')

    ->update('firstname','lastname')

    ->values('Muhammad Afif','Tahir')

    ->where('email','=','afif@gmail.com')

    ->run();

    }

  • Example delete data:
    
                              

    public static function delete(){

    Query::delete('users')

    ->where('id','=',1)

    ->run();

    }

Requests

To get instance of the current HTTP request from the application, your need to import the libraries of request class on your file controller.

Your can type this code use Dedelang\Http\Request; in header your file controller.


  • Example GET method:
                                

    <?php

    namespace Controllers;

    use Dedelang\View\View;

    use Models\UserModel;

    use Dedelang\Http\Request;

    class UserController{

    public static function user(){

    echo Request::get('1');

    }

    ?<

    // Note: value 1(one) means the first parameter in your link.

  • Example POST method:
                                

    <?php

    namespace Controllers;

    use Dedelang\View\View;

    use Models\UserModel;

    use Dedelang\Http\Request;

    class UserController{

    public static function user(){

    echo Request::post('firstname');

    }

    ?<

    // Note: firstname means the name of input field in your form.

Views

The view function is processed to invoke the html template in folder views.

  • Example Models Class:
                                  

    <?php

    namespace Controllers;

    use Dedelang\View\View;

    use Models\WelcomeModel;

    class WelcomeController{

    public static function index(){

    View::render('Welcome',[‘name’=>’Rosmiati’]);

    }

    }

    ?>

    Note: The first argument in view function is the name of file in directory App/views.
    The second argument is an array data that will be available to display in view section.

Session

The session class can store unique information for logged in users. The Session class also can allow you to manage user’s ‘level’ and track every activity while they browse your site. In Dedelang framework have 6 function you can use in session class:

  • Example Set Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    Session::set('name','Afif');

    }

    ?<

  • Example Get Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    echo Session::get('name');

    }

    ?<

  • Example Remove Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    Session::remove('name');

    }

    ?<

  • Example Has Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    Session::has('name');

    }

    ?<

  • Example All Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    Session::all();

    }

    ?<

  • Example Destroy Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Session;

    class WelcomeController{

    public static function index(){

    Session::destroy();

    }

    ?<

Cookies

The function cookies class same as session class but the different is the cookies values store in client site and session value store in server site. In Dedelang framework has 6 function you can use in cookies class:

  • Example Set Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    Cookie::set('name','Afif');

    }

    ?<

  • Example Get Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    echo Cookie::get('name');

    }

    ?<

  • Example Remove Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    Cookie::remove('name');

    }

    ?<

  • Example Has Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    Cookie::has('name');

    }

    ?<

  • Example All Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    Cookie::all();

    }

    ?<

  • Example Destroy Method:
                                

    <?php

    namespace Controllers;

    use Dedelang\Http\Cookie;

    class WelcomeController{

    public static function index(){

    Cookie::destroy();

    }

    ?<

Validation

The validation function in Dedelang framework to make verify input data from the user before store the data into database. All process validation much be done before your do the CRUD process in the system.


  • Example required field:
                                        

    public static function insert(){

    Validate::field('firstname')

    ->required();

    }

  • Example validation email field:
                                        

    public static function insert(){

    Validate::field('email')

    ->email();

    ->required();

    }

  • Example validation maximum value:
                                        

    public static function insert(){

    Validate::field('number')

    ->max(100);

    ->required();

    }

  • Example validation minimum value:
                                        

    public static function insert(){

    Validate::field('number')

    ->min(10);

    ->required();

    }

  • Example validation only number:
                                        

    public static function insert(){

    Validate::field('number’')

    ->number();

    ->required();

    }

  • Example validation only character:
                                        

    public static function insert(){

    Validate::field('name')

    ->string();

    ->required();

    }

  • Example validation only float:
                                        

    public static function insert(){

    Validate::field('number')

    ->float();

    ->required();

    }

  • Example validation link:
                                        

    public static function insert(){

    Validate::field('url')

    ->link();

    ->required();

    }

  • Example validation file:
                                        

    public static function insert(){

    Validate::files('images')

    -> extension ('png','jpg','jpeg');

    }

  • Example Custom error message:
                                        

    public static function insert(){

    Validate::field('firstname')

    ->required('your custom error message here');

    }

  • Example redirect if have error validation:
  • Example redirect error page:
                                        

    public static function insert(){

    Validate::field('firstname')

    ->required();

    Validate::redirect('your-return-path');

    }

Firewall

Dedelang firewall is web application firewall that protect the web application from the attack such as SQL injection, command injection, cross-site scripting etc.
The engine of Dedelang firewall wil be block malicious action based on OWASP vulnerability.
If you want to know more about the OWASP vulnerability you can refer this link https://www.owasp.org.


  • Example alert message from Dedelang Firewall:
    
                                                

Zeref command

Zeref is the command-line interface in Dedelang Framework. It give the easy and shortcut process to build your application. To know details about zeref command, you can use the -help or -h command:

  • Start new project
    
                                                  

    php zeref start-project

  • Start new Module

    Command new module will be created file model, view and controller.
    For example we want created module for Users we can write the command below:

    
                                                  

    php zeref -m Users

Authentication

To make the authentication process just follow step below:

  • Step 1: Run command
    
                                                  

    php zeref make:auth

  • Step 2: Apply the path

    Copy the code below into file web.php:

    
                                                  

    Route::set('login','Login@index'); Route::set('logout','Login@Logout'); Route::set('register','Login@register'); Route::authorization('users','login')->set('users','Users@index');

  • Step 3: Access link

    Register Page:

    
                                                  

    localhost/blog/register

    Login Page:

    
                                                  

    localhost/blog/login