1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Tamtamchik\SimpleFlash\TemplateInterface; |
4
|
|
|
use Tamtamchik\SimpleFlash\BaseTemplate; |
5
|
|
|
|
6
|
|
|
if (!session_id()) @session_start(); |
|
|
|
|
7
|
|
|
|
8
|
|
|
require_once '../../vendor/autoload.php'; |
9
|
|
|
|
10
|
|
View Code Duplication |
class Bootstrap5DismissibleTemplate extends BaseTemplate implements TemplateInterface |
11
|
|
|
{ |
12
|
|
|
protected $prefix = ''; // every line prefix |
13
|
|
|
protected $postfix = '<br>'; // every postfix |
14
|
|
|
protected $wrapper = '<div class="alert alert-%s alert-dismissible fade show" role="alert"> |
15
|
|
|
%s |
16
|
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> |
17
|
|
|
</div>'; // wrapper over messages of same type |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @param $messages - message text |
21
|
|
|
* @param $type - message type: success, info, warning, error |
22
|
|
|
* |
23
|
|
|
* @return string |
24
|
|
|
*/ |
25
|
|
|
public function wrapMessages($messages, $type) |
26
|
|
|
{ |
27
|
|
|
$type = ($type == 'error') ? 'danger' : $type; |
28
|
|
|
|
29
|
|
|
return sprintf($this->getWrapper(), $type, $messages); |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
flash()->setTemplate(new Bootstrap5DismissibleTemplate()) |
34
|
|
|
->error(['Invalid email!', 'Invalid username!']) |
35
|
|
|
->warning('Warning message.') |
36
|
|
|
->info('Info message.') |
37
|
|
|
->success('Success message!'); |
38
|
|
|
|
39
|
|
|
?> |
40
|
|
|
|
41
|
|
|
<!doctype html> |
42
|
|
|
<html lang="en"> |
43
|
|
|
<head> |
44
|
|
|
<meta charset="UTF-8"> |
45
|
|
|
<title>Test Bootstrap default template example.</title> |
46
|
|
|
<!-- Latest compiled and minified CSS --> |
47
|
|
|
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous"> |
48
|
|
|
</head> |
49
|
|
|
<body> |
50
|
|
|
|
51
|
|
|
<div class="container" style="width: 600px; margin: 1em auto;"> |
52
|
|
|
<?= flash() ?> |
53
|
|
|
</div> |
54
|
|
|
|
55
|
|
|
<!-- Latest compiled and minified JavaScript --> |
56
|
|
|
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-b5kHyXgcpbZJO/tY9Ul7kGkf1S0CWuKcCD38l8YkeH8z8QjE0GmW1gYU5S9FOnJ0" crossorigin="anonymous"></script> |
57
|
|
|
|
58
|
|
|
</body> |
59
|
|
|
</html> |
60
|
|
|
|
If you suppress an error, we recommend checking for the error condition explicitly: