GithubHelp home page GithubHelp logo

smokietr / mikro Goto Github PK

View Code? Open in Web Editor NEW

This project forked from yidemir/mikro

0.0 1.0 0.0 102 KB

Fast and useful micro application framework

Home Page: https://yidemir.github.io/mikro/

PHP 100.00%

mikro's Introduction

yidemir/mikro

Fast and useful micro application framework

Installation

composer require yidemir/mikro

Features

  • String encryption/decryption
  • Database functionality (create, read, update, delete, querying)
  • Pagination (array pagination)
  • Request processing
  • Response methods
  • Router (methods, groups, resources)
  • Validator (simple validation)
  • View (simple layout and blocks)
  • Session, Cookie, CSRF and Flash message components
  • Logging, event handling and HTML generation components
  • and much more

Usage

route\get('/', function() {
    return response\view('homepage', ['param' => 'data']);
});

route\post('/save', function() {
    return response\json(['foo' => 'bar']);
});

route\put('/update/:id', function($id) {
    $data = request\input(['title', 'body', 'tags', 'created_at']);

    db\table('posts')->update($data, $id);
    flash\push('post updated!');
    
    return response\redirect('/');
});

route\group([
    'path' => '/admin',
    'namespace' => 'App\Controllers\Admin\\',
    'middleware' => ['App\Middlewares\CheckAdmin'],
    'name' => 'admin.'
], function() {
    route\get('/', 'DashboardController@index', 'home');

    route\resource('/posts', 'PostController');

    route\resource('/categories', 'CategoryController', [
        'only' => 'index|show|create|store'
    ]);

    route\resource('/items', new class {
        public function index()
        {
            $items = db\table('items')->get();

            return response\view('items.index', compact('items'));
        }

        public function show($id)
        {
            $item = db\table('items')->find($id);

            return response\view('items.show', compact('item'));
        }
    });

    route\get('/foo', function() {
        return response\html('admin panel');
    });
});

route\error(function() {
    if (request\is_ajax()) {
        return response\json(['foobar' => 'bazqux']);
    } else {
        return response\view('errors/404');
    }
});

route\run();

Database examples

$items = db\table('items')->get('where weight=? order by created_at desc', [37]);

$item = db\table('items')->find('where is_new=:is_new and foo=:foo', [
    'is_new' => true,
    'foo' => 'bar'
]);

$itemCount = db\table('items')->select('count(*)')->column('where foo=?', ['bar']);

$items = db\query('select * from items')->fetchAll();

$item = db\query('select * from posts where id=?', [100])->fetch();

$itemCount = db\query('select count(*) from items')->fetchColumn();

more examples in examples directory.

mikro's People

Contributors

yidemir avatar

Watchers

 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.