Let's get started!

Dframe

Dframe is a PHP framework to build web applications, APIs and microservices. It also has many useful components such as:

Main principle of this framework is quick creation applications. It is being developed by a group of programists and GITHUB community. Dframe is compatible with PHP 7.x.

start.min.jpg

Basic File Structure

Bootstrap.php - Contains global available variables. It's a basic class that's available in the whole proejct and is loaded at the start. Access also through variable $this->baseClass. In the example project, it contains loading of sessions, tokens, and database loading.

Config - the folder contains configuration files in form.

return [
    'key' -> 'Value',
    'anotherKey' => 'Another Value'
];

In our case, there's also router.php, since the example application uses Dframe\Router and view folder with the smarty.php file, since we used the S.M.A.R.T.Y engine, but you can use any system to render html, ex: Twig, Mustache, or pure php

Controller - the key file here is Controller.php It connects the Router and the earlier mentioned $this->baseClass

Attention!

  • All classes in this folder have to inherit the class that calls to them. extention Controller\Controller
  • Instead of __construct() we use the init() method - it works in the same way

View - This folder is responsible for the access layer not available directly from the adress.

  • index.php can be midified in any way, and methods can be added that will be available in the template - for example, an authorization class. By using $this->assign('auth', new auth());, you can easily, for example, define the showed content. In the template, the {if $auth->isLogin()} Treść Tylko dla zalogowanej osoby {/if} method is shown by the example of the used engine.
  • config.php general configuration that's available for debug, name and version of the application, as well as the adress under which it functions both for dev and the production.
|   composer.json
|   composer.lock
|   LICENSE
|
+---app
|   |   Bootstrap.php
|   |
|   +---Config
|   |   |   router.php
|   |   |
|   |   \---view
|   |           smarty.php
|   |
|   +---Controller
|   |       Controller.php
|   |       Page.php
|   |
|   \---View
|       |   Index.php
|       |   View.php
|       |
|       +---templates
|           |   footer.html.php
|           |   header.html.php
|           |   index.html.php
|           |
|           +---errors
|           |       404.html.php
|           |
|           +---page
|                 test.html.php
|
+---vendor
\---web
    |   config.php
    |   index.php
    |
    +---assets

restful.jpg

Friendly links

For safety reasons, it's recommended in the production version to use.

RewriteEngine On

#Deny access for hidden folders and files
RewriteRule (^|/)\.([^/]+)(/|$) - [L,F]
RewriteRule (^|/)([^/]+)~(/|$) - [L,F]

#Set root folder to web directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1

#Redirect all queries to index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/index.php [QSA,L]
#Set root folder to web directory
location / {
    root   /home/[project_path]/htdocs/web;
    index  index.html index.php index.htm;
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }
}

#Redirect all queries to index file
location ~ .php$ {
    try_files $uri = 404;
    fastcgi_pass 127.0.0.1:9000;
    #fastcgi_pass unix:/run/php/php7.1-fpm.sock;
    fastcgi_index web/index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}