Skip to content

Commit 6668585

Browse files
committed
bug fixes
1 parent cf0fa42 commit 6668585

File tree

5 files changed

+39
-9
lines changed

5 files changed

+39
-9
lines changed

composer.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "arojunior/php-orm-pdo",
3+
"description": "Micro PHP ORM Framework to solve basic problems",
4+
"version": "1.0",
5+
"authors": [
6+
{
7+
"name": "Junior Oliveira",
8+
"email": "[email protected]"
9+
}
10+
],
11+
"require": {
12+
"php": ">=5.4.0"
13+
}
14+
}

core/controller/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private function loadModels()
2222
{
2323
if (isset($this->use)) {
2424
foreach ($this->use as $model) {
25-
require './model/'.$model.'.php';
25+
require './app/model/'.$model.'.php';
2626
$this->{$model} = new $model();
2727
}
2828
}

core/helper/Helper.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ public function json($dados)
99

1010
array_walk_recursive($dados, function (&$value, $key) {
1111
if (is_string($value)) {
12-
$value = utf8_encode(self::removerAcentos($value));
12+
$value = utf8_encode(self::clean($value));
1313
}
1414
});
1515

1616
return json_encode($dados);
1717
}
1818

19-
public function removerAcentos($string)
19+
public function clean($string)
2020
{
2121
$table = array(
2222
'?' => 'S', '?' => 's', '?' => 'Dj', '?' => 'dj', '?' => 'Z',
@@ -37,8 +37,7 @@ public function removerAcentos($string)
3737
'ª' => '',
3838
);
3939

40-
// Traduz os caracteres em $string, baseado no vetor $table
41-
$string = strtr($string, $table);
40+
$string = strtr($string, $table);
4241

4342
return $string;
4443
}

core/model/Model.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
//namespace SimpleORM\core\model\Model;
3+
//namespace SimpleORM\Model;
44

55
require_once 'Database.php';
66

@@ -57,7 +57,7 @@ public function find($dados = null)
5757

5858
$fields = (isset($this->dados['fields'])) ? self::fields() : '*';
5959
$table = self::table();
60-
$where = (isset($this->dados['conditions'])) ? self::conditions('AND') : '';
60+
$where = (isset($this->dados['conditions'])) ? self::conditions(' AND ') : '';
6161
$sql = "SELECT {$fields} FROM {$table} {$where}";
6262
$this->stmt = $this->conn->prepare($sql);
6363

index.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,32 @@
66
require_once __DIR__.'/core//model/Model.php';
77
require_once __DIR__.'/core/controller/Controller.php';
88
require_once __DIR__.'/core/helper/Helper.php';
9+
require_once __DIR__.'/app//model/AppModel.php';
910

1011
$uri = $_SERVER['REQUEST_URI'];
1112

13+
switch ($_SERVER['REQUEST_METHOD']) {
14+
case 'GET': $the_request = &$_GET;
15+
break;
16+
case 'POST': $the_request = &$_POST;
17+
break;
18+
default:
19+
$the_request = null;
20+
}
21+
1222
if ($uri == '/') {
13-
echo 'No file selected';
23+
$response = ['response' => 'No content to show'];
24+
echo json_encode($response);
1425
} else {
1526
$src = explode('/', $uri);
1627
$model = ucfirst($src[1]);
1728
$controller = $model.'Controller';
1829
$method = (isset($src[2])) ? $src[2] : 'index';
1930

31+
if (isset($src[3]) && empty($the_request)) {
32+
$the_request = filter_var($src[3], FILTER_SANITIZE_STRING);
33+
}
34+
2035
/*
2136
* require files of current Model/Controller
2237
*/
@@ -37,7 +52,9 @@
3752
/*
3853
* call current class/method
3954
*/
40-
$set = call_user_func_array(array(new $controller(), $method), $_POST);
55+
//$set = call_user_func_array(array(new $controller(), $method), $the_request);
56+
$class = new $controller();
57+
$set = $class->$method($the_request);
4158

4259
/*
4360
* Declare all variables if passed in return

0 commit comments

Comments
 (0)