Git Product home page Git Product logo

evas-example's Introduction

evas-example

Example of application with evas php framework

System requirements

PHP 7.2+

Installation

  1. Install Composer https://getcomposer.org/download/

  2. Run command

composer install

Routing info

Handlers policy

  1. File handler:
$router->get('/login', 'login.php');
  1. Callable handler:
$router->get('/login', function () {});
  1. Class method handler:
$router->post('/login', [AuthController::class => 'login']);
  1. Handlers list:
$router->get('/login', [
    AuthController::class => 'login',
    'login.php',
]);

For use url parts in handler args

$router
    ->alias(':id', '(:int') // set alias for id
    ->get('/user/:id', function ($user_id) {
        echo "user with id = $user_id<br>";
    })

Map and Auto Router, grouping

  1. The main router is Map router
(new Router) // init Router
    ->post('/login', [AuthController::class => 'login']) // set handler to POST /login
    ->routingByRequst(App::request()) // routing by request
    ->handle(); // handle routing result
  1. Set inner Map and Auto router
(new Router) // init Router
    ->default('404.php') // set default handler
    ->middlewares([ // set global middlewares
        [Tracker::class => 'trackVisit'],
        [AuthController::class => 'setAuthUser']
    ])
    ->post('/login', [AuthController::class => 'login']) // set handler to POST /login
    ->routingByRequst(App::request()) // routing by request
    ->map('/api/v4') // set child map router to ALL /api/v4
        ->default('apiV4_404.php') // set child map router default handler
        ->middleware(function () {  // set middleware to child map router
            // check access
        })
        ->map('/user', 'GET') // set child map router to GET /api/v4/user
            ->get('/list', [UserController::class => 'list'])
            ->next() // move to parent router
        ->next() // move to parent router
    ->autoByFile('/', 'GET') // set child auto router to GET /
        ->filePostfix('.php') // set auto router file postfix
        ->next() // move to parent router
    ->handle(); // handle routing result

Database

Init

Create db.php in ./config with:

return [
    'dbname' => 'database_name',
    'username' => 'username_database',
    'password' => 'password_database',
];

Evas\Orm\Integrate\AppDbTrait has methods for getting, setting and initial single database

Evas\Orm\Integrate\AppDbsTrait has methods for getting, setting and initial multiple database

Usage this trait in your App

class App extends \Evas\Web\App
{
    use \Evas\Orm\Integrate\AppDbTrait;
}

$qr = App::db()->query('SELECT * FROM users');
var_dump($qr->assocArrayAll());

query() returned Evas\Orm\QueryResult object

Get the number of rows returned.

$rowCount = $qr->rowCount();

Get the record as a numbered array.

$numericArray = $qr->numericArray();

Get all records as an array of numbered arrays.

$numericArrayAll = $qr->numericArrayAll();

Get the record as a associative array.

$assocArray = $qr->assocArray();

Get all records as an array of associative arrays.

$assocArrayAll = $qr->assocArrayAll();

Get the record as a class object.

$classObject = $qr->classObject();

Get all records as class objects.

$classObjectAll = $qr->classObjectAll();

evas-example's People

Contributors

evasyakin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.