Skip to content

amadeuszxd/dframe

 
 

Repository files navigation

Dframe - PHP Framework

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

The basic tools to build simple and complex pages.

  1. Installation

  2. Overview

  3. Extensions

Language Polish | English - coming soon

Installation

$ composer require dframe/dframe

Before run add to .htaccess

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/$1

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ web/index.php [QSA,L]

Overview

1. Controller file it is very important for dynamic routing. If you created file TaskForRouter.php with class with method ActionForRouter() your \Dframe\Router url will look like yourpage.com/TaskForRouter/ActionForRouter

app/Controller/TaskForRouter.php:

<?php
namespace Controller;

Class TaskForRouterController extends \Controller\Controller
{
    public function ActionForRouter(){
         $exampleModel = $this->loadModel('Example'); #Load model
         $view = $this->loadView('Index'); #Load view
         
         $getId = $exampleModel->getId($_GET['id']); #Call method
         $view->assign('varForSmarty', $getId); #Set variable to view
         return $view->render('exampleNameFile'); #Generate view app/View/templates/exampleNameFile.tpl
    }
}

2. Model is not required in project if you are not using any databases

app/Model/ExampleModel.php:

<?php
namespace Model;

Class ExampleModel extends Model\Model
{
    public function getId($id){
        return $this->baseClass->db->pdoQuery('SELECT * FROM table WHERE id = ? LIMIT 1', array($id))->result();
    }
}

3. View receiving data from Controller and can display more advanced template. You dont have to use view if you using dframe only for xml/json/jsonp it can do controler without templates files

You can use php, twig, *smarty or write own View engine

<?php
namespace Dframe\View;

interface ViewInterface
{

    /**
     * Set the var to the template
     *
     * @param string $name 
     * @param string $value
     *
     * @return void
     */

    public function assign($name, $value);

    /**
     * Return code
     *
     * @param string $name - Filename
     * @param string $path - Alternative Path
     *
     * @return void
     */
    
    public function fetch($name, $path=null);

    /**
     * Include File
     */
    public function renderInclude($path);
     
    /**
     * Display JSON.
     * @param array $data
     */
    public function renderJSON($data);
 
    /**
     * Display JSONP.
     * @param array $data
     */
    public function renderJSONP($data);

}

S.M.A.R.T.Y example View/templates/exampleNameFile.html.php:

<html>
    <head>
        <title>SmartyNews!</title>
    </head>
<body>
    <h3>{$varForSmarty.title}</h3>
    <p>Napisał {$varForSmarty.autor} dnia {$varForSmarty.data}</p>
    <p>{$varForSmarty.description|truncate:200:"..."}</p>
</body>
</html>

License

MIT

Tech

Dframe\Database- PHP PDO Class Wrapper S.M.A.R.T.Y - Default Template Engine (available: php, twig)

About

Dframe/Dframe php Framework

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%