add user
This commit is contained in:
@ -12,4 +12,9 @@ class Controller
|
||||
$this->loader = new \Twig\Loader\FilesystemLoader(ROOT_DIR . $_ENV['VIEWS_PATH']);
|
||||
$this->twig = new \Twig\Environment($this->loader, ['cache' => ROOT_DIR . $_ENV['VIEWS_CACHE_PATH']]);
|
||||
}
|
||||
|
||||
public function redirect(string $url): void
|
||||
{
|
||||
header("Location: " . $url);
|
||||
}
|
||||
}
|
64
kernel/FormModel.php
Normal file
64
kernel/FormModel.php
Normal file
@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace kernel;
|
||||
|
||||
use app\helpers\Debug;
|
||||
use MadeSimple\Validator\Validator;
|
||||
|
||||
class FormModel
|
||||
{
|
||||
protected Validator $validator;
|
||||
|
||||
protected array $data = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->validator = new Validator();
|
||||
}
|
||||
|
||||
public function rules(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function load(array $array): void
|
||||
{
|
||||
$rules = $this->rules();
|
||||
foreach ($array as $key => $item) {
|
||||
if (isset($rules[$key])) {
|
||||
$this->data[$key] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(): array
|
||||
{
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
public function getItem(string $name)
|
||||
{
|
||||
if (isset($this->data[$name])){
|
||||
return $this->data[$name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function validate(): bool
|
||||
{
|
||||
$res = $this->validator->validate($this->data, $this->rules());
|
||||
if (!$res) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
//return $this->validator->validate($this->data, $this->rules());
|
||||
}
|
||||
|
||||
public function getErrors(): array
|
||||
{
|
||||
return $this->validator->getProcessedErrors();
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user