Re: Navigation element
I would recommend another way. gwoo's solution means a request to the db every time(!) the navigation is shown. IMHO too much db-action. I would create a function in the controls controller like function updateNavigation() { $entries = $this-Control-findAll(); $string = 'ul'; foreach ($entries as $key = $value) { $string .= li?php echo \$html-link('Link text', '/url/to/ page/') ?/li\r\n; } $string = '/ul'; // rewriting the thtml-file of the navigation-element. $fp = fopen(ROOT.DS.APP_DIR.DS.'views'.DS.'elements'.DS.'navigation.thtml', 'r+'); ftruncate($fp, 0); fputs($fp, $string); fclose($fp); } Call this function with every create and update (e.g. in add(), edit()) and it rewrites your navigation element with the newest data. so most of the request on the navigation do not need a db request. I use this in several apps and it works pretty good and saves ressources of your db. On 20 Mrz., 01:19, gwoo [EMAIL PROTECTED] wrote: This has come up a lot lately for some reason. I guess because there are not enough examples. Personally, I would setup and element. Lets calll it /app/views/ elements/menu.thtml add to this: $controls = $this-requestAction('controls/index'); foreach($controls as $control) { //do whatever} very simply this asks the controls controller to return the index method so you can display the data however you want ?php class ContolsController extends AppController { function index() { $contols = $this-Control-findAll(); //here is where the requesAction is handled so only the data is returned if(isset($this-params['requested'])) { return $controls; } $this-set('controls', $controls); } } ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
Following the same example, I've come up with something more dynamic - but unfortunatly I cannot seem to get it to work, can anyone help me? First of all, I call the element: ?php echo $this-renderElement('topmenu'); ? Then in the element, I call my menu section manager and request all menu's (through a hABTM association) to an array: ul ?php $menus = $this-requestAction('sections/rendermenu/topnav'); print_r(output: . $menus); foreach($menus['Section']['Menu'] as $menu) { print li; if ($menu['path'] == $this-here){ echo $html-link($menu['name'],$menu['path'],'class=active'); }else{ echo $html-link($menu['name'],$menu['path']); } print /li; } ? /ul The last param calls the search in the controller: ?php class SectionsController extends AppController { var $name = Sections; function rendermenu($id) { $menus = $this-Section-findAll(array('name'=$id)); if(isset($this-params['requested'])) { return $menus; } $this-set('menus', $menus); //print_r($menus); } } ? Now, I get an array back, but I get a foreach error: Array ( [0] = Array ( [Section] = Array ( [id] = 1 [name] = topnav ) [Menu] = Array ( [0] = Array ( [id] = 1 [name] = Home [path] = / ) [1] = Array ( [id] = 2 [name] = News [path] = /posts/ ) ) ) ) Warning (2): Invalid argument supplied for foreach() [CORE/app/views/elements/topmenu.ctp, line 5 Anyone? Thanks very much, Tane On 3/20/07, stevenoone [EMAIL PROTECTED] wrote: I tried this solution and whaddya know: if worked! here's my code. //invoke menu element ?php echo $this-renderElement('menu'); ? //menu.thtml ul ?php $controls = $this-requestAction('controls/navindex'); foreach($controls as $control) { print li; if ($control['Control']['path'] == $this-here){ echo $html-link($control['Control']['name'],$control['Control'] ['path'],'class=active'); }else{ echo $html-link($control['Control']['name'],$control['Control'] ['path']); } print /li; } ? /ul On Mar 19, 5:19 pm, gwoo [EMAIL PROTECTED] wrote: This has come up a lot lately for some reason. I guess because there are not enough examples. Personally, I would setup and element. Lets calll it /app/views/ elements/menu.thtml add to this: $controls = $this-requestAction('controls/index'); foreach($controls as $control) { //do whatever} very simply this asks the controls controller to return the index method so you can display the data however you want ?php class ContolsController extends AppController { function index() { $contols = $this-Control-findAll(); //here is where the requesAction is handled so only the data is returned if(isset($this-params['requested'])) { return $controls; } $this-set('controls', $controls); } } ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
foreach($menus['Section']['Menu'] as $menu) { Hi, it' hard to read code in the google layout... especially pr() output...;) looks like the array is numeric... try: foreach($menus as $menu) { echo $menu['Section']['id']; pr($menu['Menu']); ... } greets, f. Array ( [0] = Array ( [Section] = Array ( [id] = 1 [name] = topnav ) [Menu] = Array ( [0] = Array ( [id] = 1 [name] = Home [path] = / ) [1] = Array ( [id] = 2 [name] = News [path] = /posts/ ) ) ) ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
Ok, well in my controller, before I pass anything I print_r my variable, and the output looks like this: Array ( [0] = Array ( [Section] = Array ( [id] = 1 [name] = topnav ) [Menu] = Array ( [0] = Array ( [id] = 1 [name] = Home [path] = / ) [1] = Array ( [id] = 1 [name] = Home [path] = / ) ) ) ) It does look rather skew-wiff to me. Here is my model: class Section extends AppModel { var $name = 'Section'; var $hasAndBelongsToMany = array( 'Menu' = array('className' = 'Menu', 'joinTable' = 'menus_sections', 'foreignKey' = 'section_id', 'associationForeignKey' = 'section_id', ), ); } So my Section model has a id and a name. Menu model has a id, name and path, and the join table (menus_sections) has a menu_id and section_id. On 3/20/07, f. [EMAIL PROTECTED] wrote: foreach($menus['Section']['Menu'] as $menu) { Hi, it' hard to read code in the google layout... especially pr() output...;) looks like the array is numeric... try: foreach($menus as $menu) { echo $menu['Section']['id']; pr($menu['Menu']); ... } greets, f. Array ( [0] = Array ( [Section] = Array ( [id] = 1 [name] = topnav ) [Menu] = Array ( [0] = Array ( [id] = 1 [name] = Home [path] = / ) [1] = Array ( [id] = 2 [name] = News [path] = /posts/ ) ) ) ) --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
@sunertl you would do better to use cache function. Also, realize that a small db query is not that painful. In any case, in 1.2 you can now cache an element using the $this-element('whatever', array('cache'='+1 day')); --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
On 3/20/07, gwoo [EMAIL PROTECTED] wrote: @sunertl you would do better to use cache function. Also, realize that a small db query is not that painful. In any case, in 1.2 you can now cache an element using the $this-element('whatever', array('cache'='+1 day')); woo hoo gwoo -- (the old fart) the advice is free, the lack of crankiness will cost you - its a fine line between a real question and an idiot http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/ --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
I'd say, likely you'll create a Model called Control And to get the list of menu items, use either the methods find() or findAll() to get data from the the Control Model instance. Explaining more than that would not help you.. make sure if you have not, you have run through the Blog Tutorial, and make sure you understand the basics of how the CakePHP framework works. http://manual.cakephp.org/appendix/blog_tutorial --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
This has come up a lot lately for some reason. I guess because there are not enough examples. Personally, I would setup and element. Lets calll it /app/views/ elements/menu.thtml add to this: $controls = $this-requestAction('controls/index'); foreach($controls as $control) { //do whatever } very simply this asks the controls controller to return the index method so you can display the data however you want ?php class ContolsController extends AppController { function index() { $contols = $this-Control-findAll(); //here is where the requesAction is handled so only the data is returned if(isset($this-params['requested'])) { return $controls; } $this-set('controls', $controls); } } ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Navigation element
I tried this solution and whaddya know: if worked! here's my code. //invoke menu element ?php echo $this-renderElement('menu'); ? //menu.thtml ul ?php $controls = $this-requestAction('controls/navindex'); foreach($controls as $control) { print li; if ($control['Control']['path'] == $this-here){ echo $html-link($control['Control']['name'],$control['Control'] ['path'],'class=active'); }else{ echo $html-link($control['Control']['name'],$control['Control'] ['path']); } print /li; } ? /ul On Mar 19, 5:19 pm, gwoo [EMAIL PROTECTED] wrote: This has come up a lot lately for some reason. I guess because there are not enough examples. Personally, I would setup and element. Lets calll it /app/views/ elements/menu.thtml add to this: $controls = $this-requestAction('controls/index'); foreach($controls as $control) { //do whatever} very simply this asks the controls controller to return the index method so you can display the data however you want ?php class ContolsController extends AppController { function index() { $contols = $this-Control-findAll(); //here is where the requesAction is handled so only the data is returned if(isset($this-params['requested'])) { return $controls; } $this-set('controls', $controls); } } ? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Cake PHP group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---