1. Go to this page and download the library: Download hezecom/slim-starter library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Controllers;
class HomeController extends Controller
{
public function index(Request $request, Response $response)
{
return view($response,'index.twig');
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
protected $table = 'users';
protected $fillable = [
'email',
'username',
'password',
];
}
namespace App\Middleware;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
class AuthMiddleware extends Middleware
{
public function __invoke(Request $request, RequestHandler $handler)
{
if(! $this->container->get('auth')->isLogin()) {
return redirect()->route('login')->with('error', 'Access denied, you need to login.');
}
$response = $handler->handle($request);
return $response;
}
}
namespace App\Controllers\Auth;
use App\Controllers\Controller;
use Respect\Validation\Validator as v;
class AuthController extends Controller
{
public function register(Request $request, Response $response)
{
$validation = $this->validator->validate($request, [
'email' => v::noWhitespace()->notEmpty()->email(),
'username' => v::noWhitespace()->notEmpty()->alnum(),
'password' => v::notEmpty()->stringType()->length(8),
]);
if ($validation->failed()) {
redirect()->route('register');
}
// more coding here
}
}