redrumak47
New Member
I am working on a codeigniter site, in which a page is built using multiple views, I have come to a point where I need to work with a variable that is being set in another view is it possible to access it from another view?This is code I haveController:\[code\] public function index() {// $this->output->enable_profiler(TRUE); $data = http://stackoverflow.com/questions/2019296/array(); if($query = $this->category_model->get_all_online()) { $data['main_menu'] = $query; } $this->load->model('image_model'); /* * Sort out the users backgrounds, basically do a check to see if there is a 'special' background * if there is not a 'special' background then IF the user is logged in and has a background of there * own show that one, if not show a generic one, if they are not logged in show a bang one */ $image = array(); if ($query = $this->image_model->get_special_backgrounds()) { $image['special'] = $query; } elseif(!isset($image['special']) && !isset($this->session->userdata['user_id'])) { if($query = $this->image_model->get_mysite_background()) { $image['generic'] = $query; } } if(isset($this->session->userdata['user_id'])) { if($query = $this->image_model->get_user_backgrounds($this->session->userdata['user_id'])) { $image['user_background'] = $query; } } $data = http://stackoverflow.com/questions/2019296/array_merge($data, $image); $this->load->view('home/main_page.php', array_merge($data, $image));}\[/code\]Model:\[code\]public function get_mysite_background() { $this->db->select('*'); $this->db->from('background'); $this->db->where('users_user_group_group_id', 1); $this->db->where('is_special', 0); $query = $this->db->get(); return $query->result_array();}public function get_special_backgrounds() { $this->db->select('*'); $this->db->from('background'); $this->db->where('is_special', 1); $query = $this->db->get(); return $query->result_array();}public function get_user_backgrounds($user_id) { $this->db->select('*'); $this->db->from('background'); $this->db->where('users_user_id', $user_id); $this->db->where('is_special', 0); $query = $this->db->get(); return $query->result_array();}\[/code\]The Views in Question: Firstly where the variable is getting set,\[code\]</div><div id="background-select"><?php$count = 0; if(isset($special)) { foreach ($special as $row) { $count ++; print '<div class="select">'; print "<a href='http://stackoverflow.com/questions/2019296/index.php/home/category/".$row['background_id']."'>$count</a>"; print '</div>'; if($count = 1) { $background = $row['background_name']; } } } if(isset($generic)) { foreach ($generic as $row) { $count ++; print '<div class="select">'; print "<a href='http://stackoverflow.com/questions/2019296/index.php/home/category/".$row['background_id']."'>$count</a>"; print '</div>'; if($count = 1) { $background = $row['background_name']; } } } if(isset($user_background)) { foreach ($user_background as $row) { $count ++; print '<div class="select">'; print "<a href='http://stackoverflow.com/questions/2019296/index.php/home/category/".$row['background_id']."'>$count</a>"; print '</div>'; if($count = 1) { $background = $row['background_name']; } } }?>\[/code\]And where I want to use the variable:\[code\]<body><div id="wrapper" style=<?php echo"background:url(/media/uploads/backgrounds/".$background.");";?>>\[/code\]The variable I looking to use \[code\]$background\[/code\]