Welcome Guest, Not a member yet? Register   Sign In
View functions accessing viewdata
#1

[eluser]Unknown[/eluser]
In my view, I am trying to keep things simple by writing some functions to do some common things.

I have something like this, where $viewdata[sortcurrent] is passed from my controller:

Code:
function sorted_by( $sortnumber, $displaytext ) {
   if ( $sortnumber == $sortcurrent ) {
   ...
   }
}

Even if I add global $sortcurrent, I still can't seem to access that variable from the function contained in my view. (It isn't exactly a global, but it is local in scope.)

To work around this, I ended up using:
Code:
function sorted_by( $sortnumber, $displaytext, $sortcurrent )

and everywhere sorted_by is called, I pass in $sortcurrent. This works, but is there a better or easier way to access the $sortcurrent from inside a function?
#2

[eluser]InsiteFX[/eluser]
var $viewdata = array();

Try that.

Enjoy
InsiteFX
#3

[eluser]bigtony[/eluser]
You should avoid putting function definitions in a view. Put it in a helper instead and then get the view to invoke the function (remember to load the helper in the controller) :
Code:
// This is in the view
<?php echo sorted_by($sortnumber, $displaytext); ?>
The above should be able to read your viewdata.




Theme © iAndrew 2016 - Forum software by © MyBB