Basic MVC (PHP) Structure

Viewed 24398

I have the following data flow for a simple login form.

User access controller PHP file. Controller includes model.php and view.php

User submits form, controller sends POST data to model methods, and gets a result back.

User is logged in, and forwarded to a different view (login success message) by the controller.

Currently my views are static HTML (no PHP), so here is my question. What is the correct way to then pass the user a welcome message, e.g "Hello, Craig!"?

Is the view allowed PHP snippets, e.g

<?php echo $username; ?> 

since the model is loaded before it in the controller file?

Thanks!

Edit: Is it better practice then to allow the view to access specific class methods e.g

<?php $user->getUsername(); ?>

as opposed to just variables?


Based on other answers, I have found a very useful article, which you may also be interested in.

http://www.nathandavison.com/posts/view/7/custom-php-mvc-tutorial-part-5-views

2 Answers
Related