1

How is the best way to show my content in architecture MVC? Actually I'm doing the following way:

<?php
class view {

    function __construct(){

    }

    function __set($var,$value){
        $this->var = $value;
    }
    function __get($var){
        return $this->var;
    }
    function render($render, $noinclude = false){
        if($noinclude == true){
            require ("view/template/".$render.".php");            
        }
        else{
            require ("view/template/headerTPL.html");
            require ("view/template/bannerTPL.html");
            require ("view/template/menuTPL.html");
            require ("view/template/".$render.".php");
            require ("view/template/footerTPL.html");
        }
    }
    function show($value){
        $this->value = $value;
    }
    function alert($value){
        echo "<script>alert('{$value}')</script>";
    }
}
?>

<div id="conteudo">
<?php require $this->menu; ?>
</div>

This is my render.php /\

Is it wrong to include the TPL? How should I do it?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • You have already made http://stackoverflow.com/questions/9780247/mvc-problems-problems-with-views and http://stackoverflow.com/questions/9760250/how-the-best-way-to-make-a-menu-with-php-mvc .. stop spamming. – tereško Mar 21 '12 at 19:21
  • oh, sorry i didnt see this topics anymore. thank u – user1258260 Mar 21 '12 at 19:33
  • they all should be here : http://stackoverflow.com/users/1258260/user1258260?tab=questions – tereško Mar 21 '12 at 19:40

1 Answers1

1

Your separating your HTML code into template files is on track, and a good way to do things. I see some HTML at the bottom of this file. I would recommend you move that into a template as well.

Just as a general guideline, the main logic of your program (controller) should never have any HTML created from it. It should pass the data (model) to the template (view) in an pure and unformatted state, then the template code will format it properly.

If you want to speed up the development of MVC programs, I would recommend you check out the CodeIgniter framework. http://codeigniter.com/

Jordan Mack
  • 8,223
  • 7
  • 30
  • 29
  • View is not a Template and Model is not an ORM. IF you suggest a read-made framework, then maybe you should suggest something that is not perversion of MVC written using PHP4-style code and dependent on global state. – tereško Mar 23 '12 at 19:08
  • @tereško Just using simple terms for those who are less experienced. The entire PHP/HTML/CSS suite is a giant hacky perversion of MVC. – Jordan Mack Mar 23 '12 at 19:12