Re: Reading data within a controller
Or you can access this data in controller's action by: $this->viewVars['variable']; This could Be helpful, id you want to acces data set in beforeFilter action (for instance in app_controller beforeFilter action On Nov 19, 6:51 am, jburns wrote: > Perfect - thanks. Here's how I've implemented it: > > $variable = $this->Controller->read(null, $id); > $this->set('path', $this->Controller->AssociatedController->getpath > ($variable['AssociatedController']['id'], 'id, name')); > $this->set(compact('variable')); > > What this allows me to do is show the hierarchical path of a related > field up to the root of the tree in the view. For example, for a > business unit based in a location (which has the tree behaviour) I can > show the path from the location where this business unit is based and > it's parents all the way to the top of the tree. > > Thanks. > > On Nov 19, 5:38 am, Erik wrote: > > > Jeremy, > > > $variable will be how you access it in the view template (ctp) file. > > If you still need it in the controller you should do: > > $variable = $this->Controller->read(null, $id); > > // Do some work with $variable. > > $this->set(compact('variable')); > > > On Nov 19, 12:30 am, jburns wrote: > > > > Once I have executed this... > > > > $this->set('variable', $this->Controller->read(null, $id)); > > > > ...within the view function of a controller, how can I access the > > > contents of 'variable'? I want to extract one or more field values of > > > the current row. I have tried using $variable, but it is not > > > recognised. > > -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-...@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=.
Re: Reading data within a controller
Perfect - thanks. Here's how I've implemented it: $variable = $this->Controller->read(null, $id); $this->set('path', $this->Controller->AssociatedController->getpath ($variable['AssociatedController']['id'], 'id, name')); $this->set(compact('variable')); What this allows me to do is show the hierarchical path of a related field up to the root of the tree in the view. For example, for a business unit based in a location (which has the tree behaviour) I can show the path from the location where this business unit is based and it's parents all the way to the top of the tree. Thanks. On Nov 19, 5:38 am, Erik wrote: > Jeremy, > > $variable will be how you access it in the view template (ctp) file. > If you still need it in the controller you should do: > $variable = $this->Controller->read(null, $id); > // Do some work with $variable. > $this->set(compact('variable')); > > On Nov 19, 12:30 am, jburns wrote: > > > > > Once I have executed this... > > > $this->set('variable', $this->Controller->read(null, $id)); > > > ...within the view function of a controller, how can I access the > > contents of 'variable'? I want to extract one or more field values of > > the current row. I have tried using $variable, but it is not > > recognised. -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-...@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=.
Re: Reading data within a controller
Jeremy, $variable will be how you access it in the view template (ctp) file. If you still need it in the controller you should do: $variable = $this->Controller->read(null, $id); // Do some work with $variable. $this->set(compact('variable')); On Nov 19, 12:30 am, jburns wrote: > Once I have executed this... > > $this->set('variable', $this->Controller->read(null, $id)); > > ...within the view function of a controller, how can I access the > contents of 'variable'? I want to extract one or more field values of > the current row. I have tried using $variable, but it is not > recognised. -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-...@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=.
Reading data within a controller
Once I have executed this... $this->set('variable', $this->Controller->read(null, $id)); ...within the view function of a controller, how can I access the contents of 'variable'? I want to extract one or more field values of the current row. I have tried using $variable, but it is not recognised. -- You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-...@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=.