General PHP MVC Question

I am creating a small MVC framework for a specific PHP application - using Doctrine as an ORM. I would like to know what would be the best way to manage the external interface.

My application has 3 menus (horizontal menu, left menu, footer / footer menu) that can be edited by the site administrator (the menu is stored in the Doctrine NestedSet).

Where should be the code that calls up and displays the menu? Each controller should be able to trigger the creation of a menu in accordance with its requirements (for example, for the controller, the user does not want to display the left menu).

Searching for this function in the menu model would be inappropriate, I think ...

+3
source share
2 answers

The controller must call the code to display the menu and use any data from your database in the Model, if necessary. Then submit the results to your view.

Here is a small breakdown

View

  • Handles web page content
  • The combination of HTML and PHP as templates.
  • Entrance and presentation

Model

  • Contains the business logic of your application.
  • Where all the data from your database will be stored.

controller

  • It receives input and requests a response from the corresponding model.
+2
source

MVC- ( Symfony, ) include ( Symfony), . , . include include, , , .

, , , .

Model

Doctrine findByX, . parent, findByParent.

$items = Doctrine::getTable('TopMenuItems')->findByParent( isset($parent) ? $parent : null) ) // null for initial call to grab top-tier elements, recursion should pass in new parent for children

<?php foreach($items as $item) : ?>
  // echo HTML element for nav item
  <?php $parent = $item['parent']; include('top_menu.php'); // call nav again to print this item children ?>
<?php endforeach; ?>

<?php if($user->wantsTopMenu()) : ?>
<?php include('top_menu.php'); ?>
<?php endif; ?>

, .

+1

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


All Articles