Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b7f7274

Browse files
Make it able to work with sub folders of controllers
1 parent 2274aea commit b7f7274

File tree

7 files changed

+8
-54
lines changed

7 files changed

+8
-54
lines changed

‎src/app/Router.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ public function redirectTo() : void
104104
if (is_callable([$controller, $action]))
105105
{
106106
unset($this->params['action']);
107+
unset($this->params['namespace']);
107108
}
108109
else
109110
{

‎src/controllers/Controller.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ public function model(string $model)
2424
* @param array $data Passing vars to the view
2525
* @return void
2626
*/
27-
public function view(string $view, array$data = []) : void
27+
public staticfunction view(string $view) : void
2828
{
29+
$file = APPROOT . '/src/views/' . $view . '.php';
2930
// Check for view file
30-
if (file_exists('../app/views/' . $view . '.php'))
31+
if (is_readable($file))
3132
{
32-
require_once '../app/views/' . $view . '.php';
33+
require_once $file;
3334
}
3435
else
3536
{
3637
// View does not exist
37-
die('View does not exist');
38+
die('<h1> 404 Page not found </h1>');
3839
}
3940
}
4041
}

‎src/controllers/Index.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@ class Index extends Controller
55
{
66
public function home()
77
{
8-
echo"<h1> Homepage </h1>";
8+
Controller::view('Index/home');
99
}
1010

1111
public function about()
1212
{
13-
echo "<h1> About </h1>";
14-
}
15-
16-
public function error404()
17-
{
18-
echo "<h1> Not found </h1>";
13+
Controller::view('Index/about');
1914
}
2015
}

‎src/controllers/Module1/Class1.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎src/controllers/Module1/Class2.php

Lines changed: 0 additions & 16 deletions
This file was deleted.

‎src/views/pages/about.php

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎src/views/pages/index.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /