1. Go to this page and download the library: Download tag/sudzy 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/ */
tag / sudzy example snippets
use Respect\Validation\Validator as v;
// Within a `ValidModel` class declaration:
public function prepareValidation()
{
$this->setValidation('username', v::alnum()->noWhitespace()->length(1, 15) );
$this->setValidation('email', v::email() );
$this->setValidation('password', v::stringType()->length(6, null)->length(1, 15) );
$this->setValidation('birthdate', v::date()->age(18));
}
namespace Models;
use Respect\Validation\Validator as v;
class User extends \Sudzy\ValidModel
{
public function prepareValidation()
{
$this->setValidation('username', v::alnum()->noWhitespace()->length(1, 15) );
$this->setValidation('email', v::email() );
$this->setValidation('password', v::stringType()->length(6, null)->length(1, 15) );
$this->setValidation('birthdate', v::date()->age(18));
}
}
// This example assumes Slim context and access to flash messages
// ... <snip> ...
$newUser = Model::factory('\Models\User')->create();
try {
$newUser->email = $_POST['email'];
$newUser->password = $_POST['password'];
$newWard->save();
$this->flash->addMessage('success', 'New User created.');
} catch (Sudzy\ValidationException $sve) {
foreach ($sve->getMessages() as $msg) {
$this->flash->addMessage('error', $msg);
}
}