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 .
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
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.
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);
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';
}
your views are in app/views
folder and every view must have .view.php
extension.
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
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