Welcome Guest, Not a member yet? Register   Sign In
Sharing data between view partials
#1

[eluser]Isuka[/eluser]
Hi,

When I build an app, I usually create a master view like this :
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;title&gt;&lt;?php echo title; ?&gt;&lt;/title&gt;  
&lt;?php echo $view_css; ?&gt;
&lt;/head&gt;
&lt;body&gt;
<div id="header">
<h1>&lt;?php echo $title; ?&gt;</h1>
</div>
<div id="content">
&lt;?php echo $content; ?&gt;
</div>
<div id="sidebar">
&lt;?php echo $sidebar; ?&gt;
</div>
<div id="footer">
&copy; mygreatwebsite.com
</div>
&lt;/body&gt;
&lt;/html&gt;

In my controller I make something like this :
Code:
class Welcome extends Controller
{
  function Welcome()
  {
    parent::Controller();    
  }    
  function index()
  {
    $data = array(
      'title'=>'My Great Title',
      'content'=>$this->load->view('content_partial_view', '', TRUE),
      'sidebar'=>$this->load->view('sidebar_partial_view', '', TRUE)
    );
    $this->load->view('master', $data);
  }
}
In my actual case, I have access to $title only in my master view but not in my content and sidebar partials. What if I want to have access to $title in my content view ? I need to make another array with the same title data specificaly for the content view. And the same goes for the sidebar view.

So I'm wondering if it's possible to have a global $data accessible for all my views (master, content and sidebar).

(I used to make partial with the great View Library by coolfactor before, but there's not update since July 2007, so I try to use the default CI View Library now Tongue)

Thanks for any helpful information Smile


Messages In This Thread
Sharing data between view partials - by El Forum - 10-15-2008, 09:53 AM
Sharing data between view partials - by El Forum - 10-15-2008, 10:31 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:05 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:11 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:19 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:23 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:33 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:54 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:12 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:43 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:47 AM
Sharing data between view partials - by El Forum - 10-16-2008, 04:27 AM



Theme © iAndrew 2016 - Forum software by © MyBB