A
A
Alexander Sharomet2015-11-20 10:19:43
PHP
Alexander Sharomet, 2015-11-20 10:19:43

How to create layout in mvc php?

Hello.
My question is:
How to create mvc with support for different layouts?
For example, earlier I wrote simply in View:

class View {
  public function render($name){
      require_once ROOT.'views/header.php';
      require_once ROOT.'views/'.$name.'.php';
      require_once ROOT.'views/footer.php';
    }
  }
}

That is, I immediately set the header (in which the menu, styles and tags) and the footer to the file, regardless of what I load there ($name.'.php').
How can you make this type of view?
<!DOCTYPE html>
<html>
<head>
  <title>Title <?=$title?></title>
</head>
<body>
  <?php echo $this->getContent(); ?> //как то так
<footer></footer>
</div>
</body>
</html>

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-11-20
@sharomet

How to create mvc with support for different layouts?

MVC itself has nothing to do with layouts at all.
Use twig with its template inheritance. This is a much more efficient way to eliminate template duplication.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question