Skip to content

Commit 54910ad

Browse files
author
erickfirmo
committed
implementação adminlte+alterações View, Model, pagination
1 parent 61b6aad commit 54910ad

27 files changed

+2295
-383
lines changed

App/Controllers/ClienteController.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,15 @@ public function update($id)
9393
]);
9494

9595
$this->alert('success', 'Cliente atualizado com sucesso !');
96-
$this->route()->redirect('/clientes/edit');
96+
return $this->route()->redirect('/clientes/edit');
9797

9898
}
9999

100100
public function destroy($id)
101101
{
102102
$cliente = (new Cliente())->delete($id);
103+
103104
$this->alert('success', 'Cliente removido com sucesso !');
104-
$this->route()->redirect('/clientes');
105+
return $this->route()->redirect('/clientes');
105106
}
106-
107-
108-
109-
110-
111107
}

App/Controllers/DividaController.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
use App\Cliente;
88
use App\DividaDoCliente;
99

10-
11-
1210
class DividaController extends Controller
1311
{
1412

@@ -18,19 +16,16 @@ public function __construct()
1816
}
1917
public function index()
2018
{
21-
$dividas = (new Divida())->paginate(2)->all();
19+
$dividas = (new Divida())->all();
2220

2321
return $this->view('/dividas/index', [
2422
'dividas' => $dividas
2523
]);
2624
}
2725

28-
29-
3026
public function create()
3127
{
3228
$clientes = (new Cliente())->all();
33-
3429
return $this->view('/dividas/create');
3530
}
3631

@@ -40,7 +35,6 @@ public function store()
4035
$divida->valor = $this->request()->input('valor');
4136
$divida->vencimento = $this->request()->input('vencimento');
4237
$divida->save();
43-
4438
$this->alert('success', 'Dívida cadastrada com sucesso !');
4539
return $this->route()->redirect('/dividas/edit');
4640
}
@@ -49,20 +43,17 @@ public function edit($id)
4943
{
5044
$divida = (new Divida())->find($id);
5145
$clientes = (new Cliente())->all();
52-
53-
5446
return $this->view('/dividas/edit', [
5547
'divida' => $divida,
5648
'clientes' => $clientes
5749
]);
58-
5950
}
6051

6152
public function show($id)
6253
{
6354
$divida = (new Divida())->find($id);
6455

65-
return $this->view('/dividas/edit', [
56+
return $this->view('/dividas/show', [
6657
'divida' => $divida
6758
]);
6859

@@ -72,7 +63,7 @@ public function update($id)
7263
{
7364
$valor = $this->request()->input('valor');
7465
$vencimento = $this->request()->input('vencimento');
75-
$divida (new Divida())->find($id);
66+
$divida = (new Divida())->find($id);
7667
$divida->update([
7768
'valor' => $valor,
7869
'vencimento' => $vencimento

Core/Model.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Model
1313
public $pivot_entity = NULL;
1414
public $pivot_parent_id = NULL;
1515
public $pivot_table = NULL;
16+
1617

1718
public function getPDOConnection()
1819
{
@@ -43,7 +44,7 @@ public function save()
4344
$stmt->bindValue($key+1, $this->$field);
4445
}
4546
$stmt->execute();
46-
define('PARAMETER', $db->lastInsertId());
47+
define('PARAMETER', $db->lastInsertId(), true);
4748
}
4849

4950
public function find($id)

Core/Router.php

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,23 +207,26 @@ public function redirect($route)
207207
{
208208
$url = array_reverse(explode('/', $route));
209209

210-
if(defined('PARAMETER'))
210+
211+
if($url[0] == 'edit')
211212
{
212-
if($url[0] == 'edit')
213-
{
214-
$redirect = '/'.$url[1].'/'.constant('PARAMETER').'/edit';
215-
} elseif($url[0] == 'show') {
216-
$redirect = '/'.$url[1].'/'.constant('PARAMETER');
217-
218-
}
219-
}else{
220-
$redirect = $route;
213+
$redirect = '/'.$url[1].'/'.constant('PARAMETER').'/edit';
214+
} elseif($url[0] == 'show') {
215+
221216

217+
$redirect = '/'.$url[1].'/'.constant('PARAMETER');
222218

219+
} else {
220+
$redirect = $route;
223221
}
222+
223+
224224

225+
225226
header('location:'.$this->getConfig('APP_URL').$redirect);
226-
exit();
227+
exit();
228+
229+
227230
}
228231

229232
public function back()

Core/View.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,26 @@ class View
77
public function __construct()
88
{
99

10-
11-
1210
require_once __DIR__.'/../views/vendor/section.php';
1311
require_once __DIR__.'/../views/vendor/alert.php';
1412
require_once __DIR__.'/../views/vendor/pagination.php';
13+
require_once __DIR__.'/../views/vendor/active-url.php';
14+
require_once __DIR__.'/../views/vendor/auth.php';
1515
require_once __DIR__.'/../helpers/route.php';
1616
require_once __DIR__.'/../helpers/url.php';
1717
require_once __DIR__.'/../helpers/partial.php';
1818

1919

20+
2021
$this->tokenGenerator();
2122
}
23+
24+
public function responseValues($values)
25+
{
26+
if($values != NULL)
27+
foreach($values as $responseName => $responseValue)
28+
$$responseName = $responseValue;
29+
}
2230

2331
public function getViewResponse($view, $values=0)
2432
{

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@
2525

2626

2727
}
28-
}
28+
}

helpers/partial.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<?php
2-
function partial($path)
2+
function partial($path, $values=NULL)
33
{
4-
include '../views/partials/'.$path.'.php';
4+
if($values != NULL)
5+
foreach($values as $responseName => $responseValue)
6+
$$responseName = $responseValue;
7+
8+
require '../views/partials/'.$path.'.php';
59
}

0 commit comments

Comments
 (0)