Welcome Guest, Not a member yet? Register   Sign In
Building a master page.
#1

[eluser]ronn[/eluser]
I'm attempting to mimic a master page concept. What I want to do is create a master view complete with header, navigation, and footer. Then when I call another view such as landing_view. I would like my page to pull in the master page and render as a complete page. So the landing_view would just have the content specific to the landing page, and pull in the master header, footer, and navigation. How would this be done in CodeIgniter? I hope I'm explaining this well.
#2

[eluser]eoinmcg[/eluser]
If I understand correctly...

views/master.php
Code:
<?php $this->load->view('header'); ?>

<?php $this->load->view('nav'); ?>

<?php
    if(isset($view))
    {
        $this->load->view($view);
    }
?>

<?php $this->load->view('footer'); ?>


and from your various controllers:
Code:
$data['view'] = 'path/to/view';
    $this->load->vars($data);
    $this->load->view('master', $data);
#3

[eluser]ronn[/eluser]
Yes, that will work, but it will not change the url correct. It will always show under the /master url, correct? Is there anyway to do it that way and still change the url?
#4

[eluser]eoinmcg[/eluser]
No, it won't change the url at all. Take a look at http://ellislab.com/codeigniter/user-gui.../urls.html

Each controller/method can load the master view and pass a view to be loaded.

For example if you have a News controller with an 'archive' method:
Code:
class News extends Controller
{
  // constructor etc

  // our archive method
  function view()
  {
    // do your thing here
    $data['view'] = 'news/archive';
    $this->load->vars($data);
    $this->load->view('master');
  }
}
This will be accessible via
http://yoursite/news/archive

If that's still not clear, browse through the user guide and take a look at http://codeigniter.com/tutorials/

Good luck
#5

[eluser]ronn[/eluser]
Thanks eoinmcg. That helps me out greatly.




Theme © iAndrew 2016 - Forum software by © MyBB