CakePHP 3.0 beta 1: Please help to use Html helper in function on view

2014-09-02 Thread Nguyễn Anh Tuấn
Dear all. This so stupid but please help me. In my cell: *app/src/View/Cell/MyCell.php* i'm use public $helpers = ['Html']; In my cell view: *app/src/Template/Cell/MyCell/display.ctp* ?php $this-Html-link('name', ['controller' = 'mycontroller', 'action' = 'myaction', 'param']); // This one work

Re: CakePHP 3.0 beta 1: Please help to use Html helper in function on view

2014-09-02 Thread José Lorenzo
Where did you put that generateLink() function? Helpers can only be used in the templates and from other helpers. What you are trying to do is not possible. You can create other helpers that can call the Html helper internally On Tuesday, September 2, 2014 1:57:30 PM UTC+2, Nguyễn Anh Tuấn

Re: HTML helper in function?

2009-08-12 Thread Martin Westin
I don't know how you do it James. I just did a quick test in a view and defining a function inline in the view will not provide that function with access to the local variables outside the function ($html, $form...) One ugly way of making it work is to make a global reference to the html helper

Re: HTML helper in function?

2009-08-12 Thread grigri
Hi Josh, With that sort of code, you'd be better off putting it in your own helper. That helper can load its own helpers, so doing links wouldn't be a problem. This thread: http://groups.google.com/group/cake-php/browse_thread/thread/f3a8243e2226c696 deals with this approach, but for radio

Re: HTML helper in function?

2009-08-12 Thread Josh
@James - The code I have up there should produce the error. Throw the $this- object reference in front of the html-link() to get the reference to a non-object error @Martin - Are you sure you can do that with an object? I think Global can only be applied to variables, no? I'll try it out of

Re: HTML helper in function?

2009-08-12 Thread brian
Pass a handle to the helper to your function: outputMenu($html, $linkTree, $level); function outputMenu($html, $array, $level) { Even better, have a look at Andy Dawson's TreeHelper. I think it's precisely what you need for this. http://bakery.cakephp.org/articles/view/tree-helper-1 Let me

Re: HTML helper in function?

2009-08-12 Thread Josh
Ahhh... passing a handle as an argument. It seems so obvious now. Thanks I have actually already moved things to a helper, which makes more sense anyway. The helper I have will suit my needs fine this time around. It will be easy to wrap tags around the menu elements when I get around to the

HTML helper in function?

2009-08-11 Thread Josh
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:

Re: HTML helper in function?

2009-08-11 Thread JamesF
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,

Re: HTML helper in function?

2009-08-11 Thread Josh
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,

Re: HTML helper in function?

2009-08-11 Thread JamesF
hmm im not sure if this will work but you could try in your element: App:import('Helper', Html'); $html = new html(); 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.

Re: HTML helper in function?

2009-08-11 Thread JamesF
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 

Re: HTML helper in function?

2009-08-11 Thread JamesF
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

Re: HTML helper in function?

2009-08-11 Thread Josh
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