Dynamic layouts in CakePHP

Sorry for the title of the question, but I could not find a more suitable way to formulate this.

I am currently creating a CakePHP-based website, and I'm not quite sure how to solve the following problem. The website looks something like this:

Website Mockup.

Shaded areas are part of the layout because their contents do not change between views. In the sidebar, I have a collection of ads that are associated with several models. I need controller logic to determine the picture associated with the advertisement. In addition, the list of ads must be dynamic. Where can I put the logic for building the sidebar?

I'm thinking of:

  • AppController (beforeFilter/afterFilter) - , ( AppController, , ).
  • - , ?
  • , - .

Cake ?


, .

, ( , ) requestAction. , .

+3
4

- , . AppController::beforeRender . , , . :

$menus = $this->NavMenuItem->groupByMenu();
$this->set( compact( 'menus' ) );

, . :

<?php echo $this->element( 'navigation', array( 'id' => 'secondary', 'menu' => $menus['SECONDARY'] ) ) ?>

, , .

+4
+5

:

  • ,
  • , , .
  • requestAction .

, , Post Model / 5 . , .

+2

,

SQL, build() , . , $user = array ( " " ); :

$Sidebar = ClassRegistry::init('Sidebar');, $Sidebar->find();, $Sidebar->build(); ..

, build() , :

  $sidebar = ClassRegistry::init('Sidebar')->build();
  $this->set('sidebar', $sidebar);

.

+2

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


All Articles