Skip to content
Slim Framework 3 skeleton application has authentication MVC construction.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app php_cs Dec 12, 2017
bootstrap php_cs Dec 12, 2017
public update home and readme May 10, 2016
resources/views update home and readme May 10, 2016
tests/unit 🎉 update phpunit demo test Mar 23, 2017
.env.example php_cs Dec 12, 2017
.gitignore fix more | add .env Mar 22, 2017
.scrutinizer.yml 🎉 update phpunit demo test Mar 23, 2017
.travis.yml 🎉 update travis.yml Mar 22, 2017
LICENSE.md LICENSE.md Mar 31, 2017
Procfile add Procfile Mar 22, 2017
README.md php_cs Dec 12, 2017
composer.json php_cs Dec 12, 2017
composer.lock php_cs Dec 12, 2017
phpunit.xml 🎉 update phpunit demo test Mar 23, 2017
slimborn.png update home and readme May 10, 2016
slimborn_2016-04-19.sql update home and readme May 10, 2016

README.md

slim-born

Scrutinizer Code Quality Build Status Code Coverage Build Status Latest Stable Version Latest Unstable Version Latest Stable Version Total Downloads License

Slim Framework 3 skeleton application has authentication MVC construction.

The user authentication has been achieved, there is a need to install and use.

Installation

composer create-project havenshen/slim-born [my-app]

.env

Copy file .env.example to .env

DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=slimborn
DB_USERNAME=root
DB_PASSWORD=
DB_PORT=3306

Router

This is a Slim Framework Router. Reference - Slim Router

<?php

$app->get('/', 'HomeController:index')->setName('home');

$app->group('', function () {
	$this->get('/auth/signup', 'AuthController:getSignUp')->setName('auth.signup');
	$this->post('/auth/signup', 'AuthController:postSignUp');

	$this->get('/auth/signin', 'AuthController:getSignIn')->setName('auth.signin');
	$this->post('/auth/signin', 'AuthController:postSignIn');
})->add(new GuestMiddleware($container));

Controller

Use Slim Framework Twig View. Reference - Twig-View

<?php

namespace App\Controllers;

class HomeController extends Controller
{
	public function index($request, $response)
	{
		return $this->view->render($response, 'home.twig');
	}
}

Model

Use Laravel PHP Framework Eloquent. Reference - illuminate/database

<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;

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

	protected $fillable = [
		'email',
		'name',
		'password',
	];

	public function setPassword($password)
	{
		$this->update([
			'password' => password_hash($password, PASSWORD_DEFAULT)
		]);
	}
}

Middleware

<?php

namespace App\Middleware;

class AuthMiddleware extends Middleware
{
	public function __invoke($request, $response, $next)
	{
		if(! $this->container->auth->check()) {
			$this->container->flash->addMessage('error', 'Please sign in before doing that');
			return $response->withRedirect($this->container->router->pathFor('auth.signin'));
		}

		$response = $next($request, $response);

		return $response;
	}
}

Validation

Use the most awesome validation engine ever created for PHP. Reference - Respect/Validation

<?php

namespace App\Controllers\Auth;
use App\Models\User;
use App\Controllers\Controller;
use Respect\Validation\Validator as v;

class AuthController extends Controller
{
	public function postSignUp($request, $response)
	{
		$validation = $this->validator->validate($request, [
			'email' => v::noWhitespace()->notEmpty()->email()->emailAvailable(),
			'name' => v::noWhitespace()->notEmpty()->alpha(),
			'password' => v::noWhitespace()->notEmpty(),
		]);

		if ($validation->failed()) {
			return $response->withRedirect($this->router->pathFor('auth.signup'));
		}

		//	todo someting
	}
}

More basic functions

reference slim official documents - Slim Framework

Use Packages

Look Feel

slimborn look feel

Directory Structure

|-- slim-born
	|-- app
		|-- Auth
		|-- Controllers
		|-- Middleware
		|-- Models
		|-- Validation
		|-- Routes.php
	|-- bootstrap
		|-- app.php
	|-- public
	|-- resources
	....

Testing

$ phpunit

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.