Note that there are some explanatory texts on larger screens.

plurals
  1. POMVC bad url error handling
    primarykey
    data
    text
    <p>I´m making a tiny MVC framework for learning purpose.</p> <p>I have a file and a class called load which is in my model folder. It reads the requested file name and checks if the file is in the views folder and returns the correct file. The problem I´m having is that I´m trying to make a handling for bad urls so that if the requested file/url does not excist you are directed to the index.php page in the views folder...</p> <p>I have an if statement inside the function that checks if the file exists and I thought I could just write an else statement requiring the index.php file incase the file was not found... But this doesn´t work. All I´m getting is a white blank page when I type in an non existing page even I´f I try echo something in the else statement...</p> <p>Does anyone know what´s missing or what I´m doing wrong?</p> <p><strong>UPDATE:</strong> Added mainController class</p> <p>This is what the hole load class looks like:</p> <pre><code>&lt;?php /* model/load.php */ class load { /* This function takes parameter * $file_name and match with file in views. */ function view($file_name, $data = null) { if (is_readable('views/' . $file_name)) { if (is_array($data)) { extract($data); } require 'views/' . $file_name; } else { //This is where I thought I could require the index.php file... } } } </code></pre> <p>And in my controller folder I have a mainController class sending the files to the load file. This is what the mainController class looks like:</p> <pre><code>&lt;?php /* controller/main.php * */ class mainController { public $load; public $urlValues; public function __construct() { $url = parse_url($_SERVER['REQUEST_URI']); $url = explode('/', trim($url['path'], '/')); $this-&gt;urlValues = array('controller' =&gt; $url[1]); //Index page if ($this-&gt;urlValues['controller'] == "index.php") { $key = array("key" =&gt; ""); $this-&gt;load = new load(); $this-&gt;load-&gt;view('index.php', $key); } //Register page if ($this-&gt;urlValues['controller'] == "register.php") { $this-&gt;load = new load(); $this-&gt;load-&gt;view('register.php'); } //Home page if ($this-&gt;urlValues['controller'] == "home.php") { $this-&gt;load = new load(); $this-&gt;load-&gt;view('home.php'); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload