Step 3 – Views
Currently the controllers echo the content themselves. The MVC pattern demands a split in presentation and domain layers. This means we need to create views which a called by the controller. A view can be as simple as a HTML file with or without PHP variables. We’ll create 2 views: ‘HelloWorld.php’ and ‘Scream.php’ and put an imagine ‘scream.jpg’ in static.
[snip php-source]code/mvctest/step3/views/HelloWorld.php[/snip]
[snip php-source]code/mvctest/step3/views/Scream.php[/snip]
These views can be simply included by the controllers.
[snip php-source]code/mvctest/step3/controllers/HelloWorld.php[/snip]
(NOTE: The views are not byte code cached. This shouldn’t be a big problem, since the view should have to much PHP code).


oops… I saw in the post “Perl like temporary variables in PHP”, you said personally you dislike MVC at all?
confused
Hi Jefflee,
I think it is not really possible to dislike something you haven’t tried. I’ve tried MVC for a few projects and did not like it. Especially for websites it is doing more bad than good. Still my remark at the other post might be a bit to harsh. MVC might be a good strategy for other types of web-apps.
Arnold
PS. You’re reading my blog really closely. Kudos to you
Hi Arnold,
First of all, thank you very much for your post, altough I found very late. I think as you are, about ‘single file entry point’ and I searched about other ways to reach VC components only.
I like your way. But I have some comments. Your .htaccess file is not working on my apache server. Therefore I used my .htacess as given below:
RewriteEngine On
RewriteRule ^$ /controllers/helloworld.php [QSA] [L]
RewriteRule ^([^/\.]+)?$ controllers/$1.php [QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)?$ controllers/$1.php?action=$2 [QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)?$ controllers/$1.php?action=$2&var=$3 [QSA]
If you are any advice about your .htaccess modification, I will be appreciated.
And the another point for views. How can we use multiple template with your approach?
Regards