PHP Frameworks - Dynamic Layout Menu

I am developing a website in PHP and I would like to use the mvc framework for this, since I want to gain experience with PHP frameworks.

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

What I need to do is create a layout that will, 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 just be done from my point of view.

This will lead to the display of menus, content and announcements from individual controllers and views and, of course, will be dynamic content. I do not want to enter the menu code in all kinds ...

Maybe it's simple, and I'm just wrong?

Any help is appreciated.

Thanks,
Ben

+3
10

Symfony , , .

  • - , .
  • - , URL- .
  • - , .
  • - , , .
  • - .

, , , , .

Symfony .

+2

, , , , , Zend Framework.

Zend_Navigation, . , Zend_Navigation Front Controller , ,

placeholder, Front Controller . , .

dustin.cassiday , . Itay Moav - Zend_Navigation

+2

PHP, , , .

. . , Smarty, , .

+1

actionStack :

$this->_helper->actionStack('menu','index');
$this->_helper->actionStack('ads','index');
+1

, , , . Smarty.

0
0

Cake ,

echo $this->element('menu');

, . , , , . , /, .

// Controller
$this->set('currentNode', 'homepage');

// Menu Element
if ($currentNode == 'homepage') {
    // add class 'selected' to menu item, or something like this
}

, , .

// Menu Element
if ($this->controller == 'home') {
    // highlight this menu item, add extra sub-items, re-calibrate flux capacitor
}

, , , . , / .

0

Zend Framework ( , , ) . .
:

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

:

class Zend_View_Helper_Menu{
   public function menu(){
       echo "<html.........>";
   }
}

class Zend_View_Helper_Ads{
   public function ads(){
       echo "<html.........>";
   }
}

, , . ,

0

Zend Framework , responseSegment ViewRenderer :

class IndexController extends Zend_Controller_Action {

    public function menuAction() {

        //menu code goes here

        $this->_helper->viewRenderer->setResponseSegment('menu');
    }

    public function adsAction() {

        //ads code goes here

        $this->_helper->viewRenderer->setResponseSegment('ads');
    }
}

....

, :

<?= $this->layout()->menu; ?>
<?= $this->layout()->ads; ?>
0

DooPHP, <!-- include 'templatefilename' --> . . - http://doophp.com/demos

0

Source: https://habr.com/ru/post/1713498/


All Articles