Discussion – Lesson 4 - Wiring controllers and views
BackComments
Member
10 messages from 23 displayed.
//= Settings::TRACKING_CODE_B ?> //= Settings::TRACKING_CODE ?>
Comments
The line $this->redirect('error');
tells the browser to
change the URL and stops the script immediately:
public function redirect($url)
{
header("Location: /$url");
header("Connection: close");
exit;
}
When a new URL is opened (error
in our case), the code of the
RouterController
is executed as you've mentioned.
But if the script is stopped, so the code that is after
else
$this->redirect('error');
that is:
// Calls the controller
$this->controller->process($parsedUrl);
// Setting template variables
$this->data['title'] = $this->controller->head['title'];
$this->data['description'] = $this->controller->head['description'];
$this->data['messages'] = $this->getMessages();
// Sets the main template
$this->view = 'layout';
should not be executed...or we have the redirect and is however processed the code at the end of RouterController?
I am in trouble to understand if,after the redirection, is however executed the remaining code or if it's stop the execution: I see that is however processed because it is set the view at 'layout' value, but so redirect doesn't stop the script...
I think I got the point:
if there isn't a valid URL, error becomes the URL and $router->process(array($_SERVER['REQUEST_URI']));
give to process method of routerController the string "error" and so the ball is passed to the errorController, right?
I get a message indicating the substantiation failed on this line of
RouterController
<code>$this->controller = new $controllerClass;</code>
The value of $controllerClass is "Controller".
The test
<code>if (file_exists('controllers/' . $controllerClass .
'.php'))</code>
returns true.
So
<code>$this->controller = new $controllerClass;</code>
translates to
<code>$this->controller = new Controller;</code>
That is the cause of the error. My research indicates that an Abstract class, like Controller, cannot be instantiated.
What am I missing or what have I done wrong?
Hi Bill, have you tried running the attached code? Perhaps you made a mistake somewhere. I've downloaded it and opened it, all worked fine for me.
Hey,
I started learning mvc, and this is the best aritcle I've found about this
topic.
I followed your instructions step by step but I always get the browser's default
error message: "The requested URL /error was not found on this server.".
I've figured out the problem is that I put the whole project into a folder
called mvc.
I spent hours to find the solution, but slowly I'm going to tear out my
hair.
I would be thanful for any ideas!
Rudi
did you just move it to the root folder or you've changed the path somewhere?
i'm tryin to change the path but can't figure it out. php noob :/
great article so far! really thorough. coupled it with stepping through the xdebug to really let the concepts sink in.
I had the same issue as Rudolf, I'd put my entire project in a sub folder in root called 'MVC' as I have several projects on my XAMP. This caused the whole app not to work and any url entered resulted in an generic error but not the error from my MVC app.
Moving the full project to root fixed the issue and now I can progress but I'm keen to learn how to keep it within a subfolder and still have my app work if anyone can explain that for me
10 messages from 23 displayed.