Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/slim-bornPublic template

Slim Framework 3 and 4 skeleton application has authentication MVC construction.

License

NotificationsYou must be signed in to change notification settings

HavenShen/slim-born

Repository files navigation

Scrutinizer Code QualityBuild StatusCode CoverageBuild StatusLatest Stable VersionLatest Unstable VersionLatest Stable VersionTotal DownloadsLicenseFOSSA Status

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.

Installation

For Slim 3

composer create-project"havenshen/slim-born v1.0.6" [my-app]

For Slim 4

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

.env

Copy file .env.example to .env

DB_DRIVER=mysqlDB_HOST=localhostDB_DATABASE=slimbornDB_USERNAME=rootDB_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(newGuestMiddleware($container));

Controller

Use Slim Framework Twig View.Reference -Twig-View

<?phpnamespaceApp\Controllers;class HomeControllerextends Controller{publicfunctionindex($request,$response){return$this->view->render($response,'home.twig');}}

Model

Use Laravel PHP Framework Eloquent.Reference -illuminate/database

<?phpnamespaceApp\Models;useIlluminate\Database\Eloquent\Model;class Userextends Model{protected$table ='users';protected$fillable = ['email','name','password',];publicfunctionsetPassword($password){$this->update(['password' =>password_hash($password,PASSWORD_DEFAULT)]);}}

Middleware

<?phpnamespaceApp\Middleware;class AuthMiddlewareextends Middleware{publicfunction__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

<?phpnamespaceApp\Controllers\Auth;useApp\Models\User;useApp\Controllers\Controller;useRespect\Validation\Validatorasv;class AuthControllerextends Controller{publicfunctionpostSignUp($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

Contributing

Feel free to submit any minor enhancements, the goal here is to keep this as simple (yet as practical) as possible.

License

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

FOSSA Status

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp