tags:

views:

153

answers:

2

I have a helper class.I have a view and controller.How can i pass a value from helper to the view?

ok Plz tell me is it possible to get he same value from the controller?

bcoz i have a div in my view while closing the div i need to call controller there i need the helper value

Advance Thanks.

A: 

Call that helper class method from the view

Rishav Rastogi
+4  A: 

You use the Helper in the View like

$return = $MyHelper->doSomething();

The Helper looks like:

Class MyHelperHelper extends AppHelper {
    function doSomething() {
        return $this->output("some value");
    }
}

$return is now "some value".

You return values just like any other function. Where's the specific problem?


UPDATE:

After seeing your updated question:

You can't "poll" data from a Controller in the View*. If you have to, you should work on your data flow. The way it's supposed to work is that the Controller prepares all the data that you need to output in advance (with the help of Models and/or Components where necessary) then passes all that data to the View. The View itself should really only be concerned with displaying the data it has been given, there should be no need for it to request any more data.

Think of the flow like this:

            Request
               |
               v
 Model <-> Controller <-> Components
               |
               v
 Elements <-> View <-> Helpers
               |
               v
Elements <-> Layout <-> Helpers
               |
               v
             Output

You can't really "reach up the chain", you can only pass data down.

*) Well, technically you can using requestAction(), but it's usually overkill and has a few implications.

Do you have any more specific code you can show to clarify your question?

deceze