1. Go to this page and download the library: Download havenshen/slim-born 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, $response)
{
return $this->view->render($response, 'home.twig');
}
}
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)
]);
}
}
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;
}
}
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
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.