I believe I've found a solution. For each possible item that can be added to the homepage I store the name of the controller that is called. By simply changing this to the model name and using App::Import in the homepage model (Where I fetch the items from the database) I have gotten rid of the requestActions.
Seems to be working quite well. >From those who are more experienced at Cake, is this a better way of doing it? On Apr 6, 10:51 am, Walther <waltherl...@gmail.com> wrote: > Hi all > > In an app that I am currently developing I wish to give the > administrator the ability to customise the home page of the app by > being able to include various other things into the home page (For > example, the admin may wish to show a welcome message which uses the > pages controller, and they may wish to show a calendar using the > calendars controller and an unlimited number of other views). > > What I am currently doing is on the homepage view I do a loop through > the homepages table and call the homepages.ctp element and sends it > the relevant data for the view that needs to be displayed. The > homepage element then calls the relevant element for whatever > controller the admin has chosen, this controller may be part of a > plugin. > > The homepages.ctp element looks as follows: > <?php > if ($item['MenuLink']['plugin_id'] == 0) > { > $View =& ClassRegistry::getObject('view'); > echo $View->element('homepages/' . $item['MenuLink']['controller'], > array('item' => $item));} > > else > { > $View =& ClassRegistry::getObject('view'); > echo $View->element('homepages/' . $item['MenuLink']['controller'], > array('item' => $item, 'plugin' => $item['MenuLink']['Plugin'] > ['directory']));} > > ?> > > As an example the homepages/pages.ctp element looks as follows: > <?php $pageToShow = $this->requestAction('/pages/index/' . $item > ['Homepage']['options']); ?> > <?php if (isset($pageToShow)) : ?> > <div> > <div id="dataInfo"> > Created: <span class="timeago" title="<?php echo > $pageToShow['Page'] > ['created']; ?>"><?php echo $date->prettyDate($pageToShow['Page'] > ['created']); ?></span><br /> > Modified: <span class="timeago" title="<?php echo > $pageToShow > ['Page']['modified']; ?>"><?php echo $date->prettyDate($pageToShow > ['Page']['modified']); ?></span><br /> > Tags: <?php echo $pageToShow['Page']['tags']; ?> > </div> > > <h1 id="nice_name"><?php echo $pageToShow['Page']['title']; > ?></h1> > <div id="content" style="margin-top:10px; text-align:left;"> > <?php > echo $pageToShow['Page']['text']; > ?> > </div> > </div> > <?php else : ?> > No page > <?php endif; ?> > > It is working well. However, I realise that requestAction is quite > intensive as it acts like another server request, is there some other > method that I can use that will achieve the same outcome but use less > server resources? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~----------~----~----~----~------~----~------~--~---