if you have time would you mind posting a test case or example code? i
would love to see some more of the code in context just so I can
improve my understanding of the issue.

please let us know what works in the end for you it might help someone
in the future

On Aug 12, 1:09 am, Josh <joshs.silver...@gmail.com> wrote:
> It works fine outside of the function. I've run into this before;
> helper functions not working within View functions. Are you sure
> you've had that work in the past?
>
> I think the issue is that you normally (in models, controllers,
> components...) need to reference the object where the function is
> located with $this-> in order to access functions accessible to the
> whole object. However, View files don't typically have their own
> classes and objects (excluding helpers) since most of the logic is
> handled elsewhere in the app.  Therefore, you get either an unknown
> method error or non-object error.
>
> I think I will throw this all in an array -> menu helper with the Html
> helper. That way I'll be able to reference the object with the link()
> function.
>
> Thanks for your help.
>
> On Aug 11, 11:15 pm, JamesF <vacationrental...@gmail.com> wrote:
>
> > hmm im not sure if this will work but you could try in your element:
>
> > App:import('Helper', Html');
>
> > $html = new html();
>
> > does html helper work in other parts of your element outside the
> > function? i usually have no problems at all using $html->link() within
> > an element function.
>
> > On Aug 11, 10:47 pm, Josh <joshs.silver...@gmail.com> wrote:
>
> > > The helpers are set and work fine. However, $html->link() does not
> > > work when called within a function in the view.
>
> > > As for where the logic is written: this is an element that appears in
> > > all admin tools throughout the site. requestAction() would allow me to
> > > put some of the logic in the controller, however since this is an
> > > array used only for constructing a menu, I don't really see any
> > > advantage to that.
>
> > > On Aug 11, 7:15 pm, JamesF <usaexportexpe...@gmail.com> wrote:
>
> > > > if your controller is set up with var $helpers = array('html') ; you
> > > > should be fine..that error is just telling you that cake can't find
> > > > HtmlHelper...is there a reason you are executing that logic in your
> > > > view and not the controller?
>
> > > > On Aug 11, 7:02 pm, Josh <joshs.silver...@gmail.com> wrote:
>
> > > > > Hi,
>
> > > > > I have the contents of a tree menu stored in a multi-dimensional
> > > > > array. The number of dimensions is not fixed, so to turn the array
> > > > > into a menu in the View file, I have set up a recurring function. This
> > > > > works fine except that I can't call the $html->link() from the
> > > > > function.
>
> > > > > Fatal error: Call to a member function link() on a non-object in...
>
> > > > > Any ideas? Is there a way to make the link() function global as you do
> > > > > a variable? There are some obvious work-arounds such as writing the
> > > > > anchor tag without the html helper, or turning the link array into a
> > > > > simpler two dimensional array where I can then iterate the link()
> > > > > function. However, I am wonder how I might specifically address the
> > > > > question of making the html->link() function available to a function
> > > > > within a view file.
>
> > > > > I have a feeling this is either going to be a simple declaration or
> > > > > not worth the trouble. Thanks in advance.
>
> > > > > Here is my code:
>
> > > > >     //array of links
> > > > >     ////key: link title
> > > > >     ////value: link location or sub-array
> > > > >     $linkTree = array(
> > > > >         'User Management' => array(
> > > > >             'Permissions' => array(
> > > > >                 'Set Permissions' => '/tools/setPermissions',
> > > > >                 'Update ACOS' => '/tools/updateacl',
> > > > >                 'View/Edit Groups' => '/admin/groups'
> > > > >             ),
> > > > >             'User Settings' => '/tools/userSettings',
> > > > >             'Users' => array(
> > > > >                 'List' => '/admin/users',
> > > > >                 'Add User' => '/admin/users/add'
> > > > >             )
> > > > >         )
> > > > >     );
>
> > > > >     //output menu function
> > > > >     function outputMenu ($array, $level) {
> > > > >         global $levelMarker;
>
> > > > >         foreach ($array as $key => $value) {
> > > > >             if (is_array($value)) {
> > > > >                 echo $level . $key;
> > > > >                 echo '<br>';
> > > > >                 outputMenu($value, $level . $levelMarker);
> > > > >             } else {
> > > > >                 echo $html->link("$level$key", $value);
> > > > >                 echo '<br>';
> > > > >             }
> > > > >         }
> > > > >         echo "<br>";
> > > > >     }
>
> > > > >     //output menu settings
> > > > >     $levelMarker = '-';
> > > > >     $level = '';
> > > > >     $linkTreeSimple = array();
>
> > > > >     //output menu
> > > > >     outputMenu($linkTree, $level);
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to