Skip to content

iya30n/micro-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

micro-framework

micro-framework is a php mvc practice something like laravel.
You can practice with that and develop that to become better.
framework branch is base framework and project branch is sample of using this.
if you want to test or run this project go here .

feautures:


Routing

you can define your routes in: app/routes.php It supports GET and POST requests for now. for example $router->get('users/all', 'UsersController@all'); is a get route. app/core/Router.php handles the routes and controllers

Request Handling

All of requests handled by app/core/Request.php. Request class contains three methods :

  • uri method: gives you current URL
  • method method: gives you the method of current URL
  • get method: gives you data of current request

how can I use it? we can use request($key) helper function . this function gets a key and returns data that assigned to key using Request::get($key). when we use all key it returns all data of request.

Query Builder

in this project I used PDO for connect to database and config file is in base path. we connect to the database using app/core/database/Connection.php Connection class. the project connect to database when app/core/bootstrap.php is run. app/core/database/QueryBuilder.php contains many methods for run useful queries that you need (find, selectAll, where, insert, etc). you can access them with Models and App binding like this: App::get('database')->find(static::$table, $id);

Models

for models we have a base model in app/core/Model.php that contains many static methods using Query Builder . also you can define new model in app/models and use it in controllers. new model must extends base model and you have to define your table name in $table static property like this:

<?php
namespace App\Model;

use App\Core\Model;

class User extends Model
{
    protected static $table = 'users';
}

Views

your views are in app/views folder and every view must have .view.php extension.

Helpers

the helper functions are in app/core/functoins.php:

  • dd : is a helper for dump data every where.
  • view : the view is a helper for loading a view using a name with your data. you can use it in controllers:
public function index()
 {
     $users = User::all();
     return view('users/index', ['users' => $users]);
 }
  • redirect : is a helper for redirect user to a route: redirect('/home')
  • validateData : is a helper for protecting input data from XSS attacks
  • request : is a helper for get data from Request

Running

for a run this project first you have to create a database and set your config on config.php then run php -S localhost:8000 in project terminal path

About

php mvc micro framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published