Skip to content

Commit a9423bc

Browse files
authored
Update Main.php
1 parent 1215f89 commit a9423bc

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

.php/Resource/Main.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,16 @@ class Main
3838
public $scripts = ['all'];
3939
public $styles = ['all'];
4040

41+
public $pathScript = false;
42+
public $pathStyle = false;
43+
4144
public $navbar = null;
4245

46+
public $patchHtml = _HTML;
47+
public $header = false;
48+
public $footer = false;
49+
public $pageName = null;
50+
4351

4452
/** Abstratic Controller constructor
4553
* -- Bypass it in your controller
@@ -68,7 +76,7 @@ function __construct($config = [])
6876
function index()
6977
{
7078
if (!file_exists(_HTML.'nopage.html')) {
71-
exit('<div style="position:absolute;top:50%;left:50%;width:300px;margin:-65px 0 0 -150px;text-align:center"><h1>Hello World!</h1>More info in <a href="https://github.com/devbr/website">Github</a>.</div>');
79+
exit('<style>h1{font-size:2em;margin:0;padding:5px 0}div{position:absolute;top:50%;left:50%;width:50%;margin:-145px 0 0 -25%;text-align:center}</style><a href="https://github.com/devbr/website"><div><h1>Hello World!</h1>More info in Github.</div></a>');
7280
}
7381
//Configuration of style & script
7482
$this->scripts = ['main'];
@@ -99,7 +107,7 @@ function indexTest($rqst, $param)
99107
function pageNotFound()
100108
{
101109
if (!file_exists(_HTML.'nopage.html')) {
102-
exit('<div style="position:absolute;top:50%;left:50%;width:300px;margin:-65px 0 0 -150px;text-align:center"><h1>Page not found!</h1>Go back to <a href="'._URL.'">homepage</a>.</div>');
110+
exit('<style>h1{font-size:2em;margin:0;padding:5px 0}div{position:absolute;top:50%;left:50%;width:50%;margin:-145px 0 0 -25%;text-align:center}</style><a href="'._URL.'"><div><h1>Page not found!</h1>Click to homepage.</div></a>');
103111
}
104112

105113
//Else...
@@ -160,6 +168,24 @@ final function sendEncriptedData($dt)
160168
}
161169

162170

171+
172+
final public function sendPage($page, $data = null, $jsvar = null)
173+
{
174+
$html = new Lib\Html();
175+
$html->setPathHtml($this->patchHtml)
176+
->body($page)
177+
->header($this->header)
178+
->footer($this->footer)
179+
->setName($this->pageName)
180+
->insertScripts($this->scripts)
181+
->insertStyles($this->styles)
182+
->val($data)
183+
->jsvar($jsvar)
184+
->render()
185+
->send();
186+
}
187+
188+
163189
/**
164190
* Cria, configura e retorna o HTML para o usuário
165191
*/
@@ -173,15 +199,19 @@ public function response(
173199
$template = null
174200
) {
175201

176-
$d = new Lib\Html(($name === null ? 'body' : $name));
202+
$d = new Lib\Html(null, ($name === null ? 'body' : $name));
203+
204+
if ($this->patchHtml !== null) {
205+
$d->setPathHtml($this->patchHtml);
206+
}
177207

178208
if ($this->navbar !== null) {
179209
$d->body($this->navbar);
180210
}
181211

182212
$d->body($body);
183213

184-
if ($name === false) {
214+
if ($template === false) {
185215
$d->header(false);
186216
$d->footer(false);
187217
}

0 commit comments

Comments
 (0)