Browse code

404 handling bug fix

RafaƂ Szklarczyk authored on 11/06/2019 21:39:30
Showing 2 changed files
... ...
@@ -234,15 +234,16 @@ class Application{
234 234
     }
235 235
 
236 236
     public function handle404($request){
237
-        if(!isset($this->router->routeInfo) && ($action = $this->router->setMatch404($request))){
237
+        if(!$this->router->is_Match404() && ($action = $this->router->setMatch404($request))){
238 238
             $this->runAction($action);
239 239
         }
240 240
         else{
241
-            echo "Resource not found!<br>".PHP_EOL;
241
+            http_response_code(404);
242
+            echo "<h1>Resource not found!</h1><br>".PHP_EOL;
242 243
             echo "<pre>";
243 244
             var_dump($request);
244 245
             echo "</pre>";
245
-            if(isset($this->router->routeInfo))
246
+            if($this->router->is_Match404())
246 247
                 throw new \Exception("The 404 controller or action not found!");
247 248
             else
248 249
                 throw new \Exception("The 404 (not found) route not set!");
... ...
@@ -136,6 +136,10 @@ class Router{
136 136
         }
137 137
     }
138 138
 
139
+    public function is_Match404(){
140
+        return isset($this->routeInfo) && ($this->routeInfo->name === _L3_ROUTE_404_NAME);
141
+    }
142
+
139 143
     public function link($name, $parameters){
140 144
         $route = $this->routeNameIndex[$name];
141 145
         $fields = array_keys($parameters);