Helpers access $this->load->vars($data) ? [take-2] |
[eluser]stormbytes[/eluser]
I originally posted this last night & thought the matter resolved. Trying to pass a variable to a Helper through a call just won't work. This is form input so it involves set_value() & validation, etc. So I'm back to my original question - I’m writing some helper functions which are called from within a view, and I’m wondering if there’s a way to write the helper function so that it can access variables loaded (from within the originating controller) through $this->load->vars($data). Perhaps some $CI method I don't know of, or some hack/workaround. Thanks!
[eluser]tonanbarbarian[/eluser]
i do not know exactly if what you are trying to do is possible, but i do know what i would do to try and see if it is in your helper grab an instance of the controller and then do a print_r of the controller and see if you can find the data you are looking for somewhere Code: function my_helper() { Code: $CI->_my_data['variable']
[eluser]InsiteFX[/eluser]
Returning views as data There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned: Code: $string = $this->load->view('myfile', '', true); CodeIgniter Views InsiteFX
[eluser]stormbytes[/eluser]
[quote author="wiredesignz" date="1289112749"] Code: $this->_ci_cached_vars; //array used by $this->load->vars() referenced from within a view. I've tried the obvious but it seems I'm missing something.. Controller: Code: $edit = array('name' =>'john', 'id'=>'5'); Helper Function: Code: $CI =& get_instances();
[eluser]stormbytes[/eluser]
left out the 'load' method/stmt. $CI->load->_ci_cached_vars works like a charm! Thanks people
[eluser]dudeami0[/eluser]
The way wiredesignz is talking about is for accessing it inside the view, and calling the helper function from there like: Code: <html> The way your going about could be done (With $CI->load->_ci_cached_vars): Code: $CI =& get_instances(); Either way should work ![]() Edit: Didn't notice your reply, I'll just leave this up here ![]()
[eluser]dudeami0[/eluser]
For a way to do this with keeping from the helper referencing the controller class is just to pass on the vars that are cached in the array. Something like this would work: Code: function myControllerFunction() { Code: function my_helper_function($vars) { and if you want variables, use the php extract function: Code: function my_helper_function($vars) { Edit: $this->load->_ci_cached_vars is actually the way from the controller
[eluser]wiredesignz[/eluser]
Code: $this->_ci_cached_vars; //array used by $this->load->vars() referenced from within a view. |
Welcome Guest, Not a member yet? Register Sign In |