php - I am new to CakePHP. Is this site menu sensible and conventional? -


i need bit of feedback make sure i'm not missing point of cakephp/mvc.

i'm designing mini-cms in cakephp--essentially photo album. i'm looking have standard, boiler-plate drop down menu on every page. naturally, menu needs dynamic user deletes , adds albums.

my goal: build moves in opposite direction of view::actionrequest() (ie, instead of view calling controller, have controller push set variable view class before renders.) understanding view::requestaction() not graceful , quite slow.

this model table containing menu keywords. app/model/modelitem.php

class menuitem extends appmodel {     public function buildmainmenu() {         return $this->find('all');     } } 

since want everywhere, put call in appcontroller

class appcontroller extends controller {     public function beforefilter() {         $this->loadmodel('menuitem');         $this->set('mainmenuitems',$this->menuitem->buildmainmenu());     } } 

and element gets dumped top of default layout css - element file: app/view/element/navigation.ctp - layout: app/view/element/layout/default.ctp

<ul id="navigation">     <?php     foreach($mainmenuitems $item) {         echo "<li>".$item['menuitem']['name']."</li>";     }     ?> </ul> 

i end lovely, bullet list of items in table. mucking up? have wrong? have no idea.

i don't see wrong approach. here few notes though, optional:

  • i'd move menu fetching code beforefilter() beforerender(). there no reason early, may throw exception before menu needed, or may redirect user page. additionally, have more information request there, can things highlight current page/item/user in menu.
  • move element rendering code sort of menuhelper, make layour cleaner (e.g. $this->menu->render() in layout). use htmlhelper render items through cake, , let cake take care of markup correctness.
  • if move rendering helper, implement sort of caching scheme whole thing, speed things - if it's necessary. whether caching possible or not, or whether should in controller or helper entirely , app :)

i guess overall advice try isolate bits of functionality rest of app; it's easier read, maintain , modify.


Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -