Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP Frameworks - Layout Dynamic Menu [closed]

I am developing a website in PHP and I would like to use a mvc framework to do this as I want to gain experience with PHP frameworks.

I have looked at Zend, CakePHP, and CodeIgniter and I have not been able to find an intuitive way to accomplish this.

What I need to do is create a layout that will be for example:

<html>
<head>
<!--scripts go here-->
</head>
<body>
<div id='banner'></div>
<div id='menu'><?php $this->layout()->menu ?></div>
<div id='container'><?php $this->layout()->content ?></div>
<div id='ads'><?php $this->layout()->ads ?>
<div id='footer'>blah</div>
</body>
</html>

I am looking for a framework that could do this simply without a lot of hacks as this should be simple to accomplish from my perspective.

This would pull the menu, content, and ads from separate controllers and views and would of course be dynamic content. I do not want to put the menu code into every view...

Maybe this is simple and I am just going about it the wrong way?

Any help is appreciated.

Thank you,
-Ben


1 Answers

Symfony can do what you are looking for using a mix of concepts.

  • Layout - This is the main structure used to decorate a page.
  • Template - This is the main view attached to a URL by the controller.
  • Fragments - Lightweight and uses data you pass to it.
  • Component - Used if you need access to the model, the code is split between presentation and logic.
  • Slot - used to replace a defined section of the layout.

In your case the layout would have the main content included using the template logic which is the core of the view layer and the other items would be either fragments or components depending on how much of the model they would need to access.

The Symfony documentation has a full explanation of this.

like image 57
Colonel Sponsz Avatar answered Aug 26 '26 03:08

Colonel Sponsz