Welcome Guest, Not a member yet? Register   Sign In
How cani pass data from one view to other

hi i am new to mvc and currently learning it i want to send data from one page to other in .net i use response.redirect() or set the postback url of the button. but i don't know how to do the same in codeigniter nd i also want to join the data of two views and display it on other view.please guide me.
Thank you

I'm not sure what exactly you're trying to get at, exactly, but with MVC, all the data is prepared before the view is loaded.

The controller takes the input from the user (either via the URL, or via post data in a form), and performs the domain logic to load the proper views and insert the data into the views like so:

$data['favorite_movie'] = 'Ghostbusters';
$data['best_friends'] = array('Mickey','Minnie','Donald','Daffy');

$data['logged_in'] = $this->user_model->is_logged_in($user_info);


You can also load views from within a view. I use this method on my site, following the pattern on Jeffrey Way's tutorial on http://net.tutsplus.com.

Here's a brief summary of how to do that:

class Site extends Controller
  function index()

    $data['content'] = 'my_other_page';
    $data['my_model_data'] = $this->my_model1->get_data();
    $data['calendar_data'] = array (
      'date' => date('Y-m-d'),
      'todays_events' => array ('soccer @ 6:00','dance @ 9:00')

$data['my_model_data'] = $my_model_data;
$other_data['calendar_data'] = $calendar_data;
<head><title>My CodeIgniter Page! :D</title>
  <link href='/css/my_style.css' />

  <div id='my_content'>
    &lt;?php $this->load->view($content,$data); ?&gt;

  <div id='my_calendar'>
    &lt;?php $this->load->view('calendar',$calendar_data); ?&gt;

  <div id='static_data'>
    &lt;?php $this->load->view('includes/static_data'); ?&gt;


And then you can use your imagination on what to do with calendar.php, {$content}.php and includes/static_data.php, but they would be located in the views folder (with static_data.php being in the includes folder therein).

Just remember that passing data to a view is easiest (I don't know if it's possible otherwise) if you pass it as an associative array, because the array keys become the variable names inside the called view. So:
$data['my_key_name'] = 'my_value';
in the constructor, or in a view, is available as:
&lt;?php echo $my_key_name; ?&gt;
in the view (if called from the constructor), or sub-view (if called from a view).

Thanks i got it ........................Smile :-)

Theme © iAndrew 2016 - Forum software by © MyBB