Load view into a variable? |
I want to load view into a variable but also want to pass some dynamic data to the view?
please help This code works: $result["view"] = $this->load->view('template/test', '', TRUE); This returns output directly to the browser: $result["view"] = $this->load->view('template/test', array("something"=>"something"), TRUE); https://codeigniter.com/user_guide/general/views.html
Can you load your snippet of code?
Codeigniter is simply one of the tools you need to learn to be a successful developer. Always add more tools to your coding arsenal!
hi just create an an array called 'anything' like this
$page_data['myvariable']='something'; // the myvariable(or whatever you write) will become a variable once passed to the view, then in the second parameter pass it there like this $result["view"] = $this->load->view('template/test', '$page_data'); // here you only pass the array name not the whole "$page_data['myvariable']" remember it dosen't have to be called myvariable it can be anything you like also page_data can be anything you like.
Hi,
You are correctly using the 3rd term set to true in the load view function. This returns the view as a string for your variable. PHP Code: $result["view"] = $this->load->view('template/test', '', TRUE); The second variable which you have left as an empty string is where you would pass the data to the partial view. PHP Code: $page_data = array('name' => 'mydata'); You can then access any of the array keys in your partial view as you would normally using, in the example above, PHP Code: My name is <?php echo $name; ?> Hope that helps, Paul.
(03-05-2016, 03:25 AM)PaulD Wrote: Hi, Hi Paul, can I perform jquery operation in test and set the value in view that value is not returned in $result["view"] view Code My Name is <?php echo $name ?> <div id="address"></div> <script> $(function(){ $('#address').html('this is my name print'); }); </script> The $result["view"] will have contains the address div value. but I'm getting an empty value. Can you guide me on that? |
Welcome Guest, Not a member yet? Register Sign In |