user1258260
user1258260

Reputation: 13

what is the best way to show menu with mvc?

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?

Upvotes: 1

Views: 1116

Answers (1)

Jordan Mack
Jordan Mack

Reputation: 8733

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/

Upvotes: 1

Related Questions