Skip to content

Commit 48d0f9b

Browse files
committed
namespaces added
1 parent 6668585 commit 48d0f9b

File tree

7 files changed

+39
-15
lines changed

7 files changed

+39
-15
lines changed

app/model/AppModel.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace SimpleORM\app\model;
4+
5+
class AppModel extends Model
6+
{
7+
public function where($dados = null)
8+
{
9+
if (!empty($dados)) {
10+
foreach ($dados as $k => $v) {
11+
if (is_int($v)) {
12+
$where[] = "{$k} = {$v}";
13+
} else {
14+
$where[] = "{$k} = '{$v}'";
15+
}
16+
}
17+
18+
return (count($where) > 1) ? implode(' AND ', $where) : ' AND '.$where[0];
19+
}
20+
21+
return null;
22+
}
23+
}

config.sample.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
db_host = 'localhost
1+
db_host = 'localhost'
22
db_user = 'root'
33
db_pass = ''
44
db_name = 'site'

core/controller/Controller.php

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

3-
//namespace SimpleORM\core\controller\Controller;
3+
namespace SimpleORM\core\controller;
44

55
class Controller
66
{

core/helper/Helper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
//namespace SimpleORM\core\helper\Helper;
2+
namespace SimpleORM\core\helper;
33

44
class Helper
55
{

core/model/Database.php

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

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

55
class Database
66
{

core/model/Model.php

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

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

5-
require_once 'Database.php';
5+
use SimpleORM\core\model\Database;
66

77
class Model extends Database
88
{

index.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
2-
2+
// Default accepting requests from everywhere. You can remove it if you want
33
header('Access-Control-Allow-Origin: *');
44
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
55

6-
require_once __DIR__.'/core//model/Model.php';
7-
require_once __DIR__.'/core/controller/Controller.php';
8-
require_once __DIR__.'/core/helper/Helper.php';
9-
require_once __DIR__.'/app//model/AppModel.php';
6+
define('DS', DIRECTORY_SEPARATOR);
7+
8+
use SimpleORM\core\helper\Helper;
9+
use SimpleORM\core\model\Model;
10+
use SimpleORM\core\controller\Controller;
11+
use SimpleORM\core\model\AppModel;
1012

1113
$uri = $_SERVER['REQUEST_URI'];
1214

@@ -35,13 +37,13 @@
3537
/*
3638
* require files of current Model/Controller
3739
*/
38-
$model_file = __DIR__.'/app/model/'.$model.'.php';
40+
$model_file = __DIR__ . DS .'app' . DS. ' model ' . DS . $model.'.php';
3941

4042
if (file_exists($model_file)) {
4143
require_once $model_file;
4244
}
4345

44-
$controller_file = __DIR__.'/app/controller/'.$controller.'.php';
46+
$controller_file = __DIR__ . DS . 'app' . DS . 'controller' . DS . $controller.'.php';
4547

4648
if (file_exists($controller_file)) {
4749
require_once $controller_file;
@@ -52,7 +54,6 @@
5254
/*
5355
* call current class/method
5456
*/
55-
//$set = call_user_func_array(array(new $controller(), $method), $the_request);
5657
$class = new $controller();
5758
$set = $class->$method($the_request);
5859

@@ -68,7 +69,7 @@
6869
/*
6970
* If method has a view file, include
7071
*/
71-
$view_file = __DIR__.'/app/view/'.$model.'/'.$method.'.php';
72+
$view_file = __DIR__ . DS . 'app' . DS . 'view' . DS . $model . DS . $method .'.php';
7273

7374
if (file_exists($view_file)) {
7475
include $view_file;

0 commit comments

Comments
 (0)