Slim Framework 3 和 4 的骨架应用程序具有身份验证 MVC 构建。
Slim Framework 3 or 4 skeleton application has authentication MVC construction.
The user authentication has been achieved, there is a need to install and use.
composer create-project "havenshen/slim-born v1.0.6" [my-app]composer create-project "havenshen/slim-born 2.0" [my-app]Copy file .env.example to .env
DB_DRIVER=mysql
DB_HOST=localhost
DB_DATABASE=slimborn
DB_USERNAME=root
DB_PASSWORD=
DB_PORT=3306This is a Slim Framework Router. Reference - Slim Router
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));Use Slim Framework Twig View. Reference - Twig-View
view->render($response, 'home.twig');
}
}Use Laravel PHP Framework Eloquent. Reference - illuminate/database
update([
'password' => password_hash($password, PASSWORD_DEFAULT)
]);
}
}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;
}
}Use the most awesome validation engine ever created for PHP. Reference - Respect/Validation
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
}
}reference slim official documents - Slim Framework
|-- slim-born
|-- app
|-- Auth
|-- Controllers
|-- Middleware
|-- Models
|-- Validation
|-- Routes.php
|-- bootstrap
|-- app.php
|-- public
|-- resources
....$ phpunitFeel free to submit any minor enhancements, the goal here is to keep this as simple (yet as practical) as possible.
The MIT License (MIT). Please see License File for more information.
暂无开放 Issues,或尚未同步最近议题。