Welcome Guest, Not a member yet? Register   Sign In
multiple views per controller
#51

[eluser]bijon[/eluser]
@craig Rodway

The example you showed that is one of the way to do that . But in that case for each view,you have to load the view
Quote:<?php $this->load->view('header'); ?>
<?php $this->load->view('menu'); ?>
<?php $this->load->view('footer'); ?>

What i want to do that is ..

/application/views/header.php
Quote:<html>
<head>
<title>My CI Site</title>
<!-- add extra javascript, -->
<?php echo (isset($extra)) ? $extra : '' ?>
</head>

<body>
/application/views/menu.php
Quote:<div id="menu"> Here is the Menu </div>
/application/views/footer.php
Quote:<div id="footer">@copyright 2008 CI Master Page</div>

And NOw i will combine the header , footer and Menu in my Master_Page Class

/application/libraries/Master_Page.php
Quote: class Master_Page {

function Master_Page() {
parent::Controller();
$this->load->view(’header’);
$this->load->view(’menu’);
$this->load->view(’footer’);
}

}

In the controller i just extends the Master_Page Class.As a result the header,menu,footer will be construct . I just call only the content view.
/application/controllers/whatever.php
Quote:class Whatever extends Master_Page {

function index() {
$this->data->test = ‘This will diplay in the Contet .’;
$this->load->view(’content’, $this->data);
}

}

And in the Content View i do not load the the header,footer and menu
like
/application/views/content.php
Quote:<div id="content">
&lt;?php echo $data; ?&gt;
</div>

When this Content View load, It will also show the Header, Footer , Menu .

Thanks
#52

[eluser]Craig A Rodway[/eluser]
You don't need to split your template up into spearate files - just have one file that contains the menu and header etc. in one page instead of loading the views separately. It will be quicker as less files have to be got from disk, and easier to maintain one piece of code rather than several loosely-connected chunks.

If you wanted to do it a different way, do this in the controller:

Code:
class Whatever extends Controller {

  function index() {
    // Data to send to the header view
    $head['extra'] = 'extra stuff for the header';

    // Now load the header view into main data array- we can access this in the view using $head
    $data['head'] = $this->load->view('head', $head, TRUE);

    // Main content here - we can access this in the view by $test
    $data['test'] = 'This will diplay in the Contet .';

    $this->load->view('content', $data);
  }

}

Template

Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;My CI Site&lt;/title&gt;

&lt;?php echo $head; ?&gt;

&lt;/head&gt;
&lt;body&gt;


  <div id="menu">
    Menu code here...
  </div>

  <div id="content">
    &lt;?php echo $test; ?&gt;
  </div>

  <div id="footer">
     This is my footer
  </div>

&lt;/body&gt;
&lt;/html&gt;
#53

[eluser]E1M2[/eluser]
Contrary to my belief the other day, I ended up missing the CF View Lib way of doing things :red: ,
what can I say, it clicks in all the right places.


CF's View Library
#54

[eluser]esra[/eluser]
[quote author="E1M2" date="1202403171"]Contrary to my belief the other day, I ended up missing the CF View Lib way of doing things :red: ,
what can I say, it clicks in all the right places.


CF's View Library[/quote]

I am of the same opinon. The View library approach seems to be more in line with following the MVC architectural pattern, plus the View library provides a level of abstraction, allowing the library to be extended if special treatment is required for different user agents or possibly different kinds of view construction (e.g., xsl/xslt).

The general concept might have been better if the library's functionality was subdivided into two librares--one to handle the structural control aspects of a view (i.e., physical assembly of the entire rendered document) and another to handle view rendering (i.e., the actual presentation of the view, possibly using a plugin-like approach to handle PHP templating and various template engine solutions).
#55

[eluser]Xeoncross[/eluser]
Hey this seems like a good feature - but I didn't even know it was missing! Out of all the things I have built with CI - I have never needed to just "print" out more than one view. Usually I just have little "widget" like views that I place in other views. So I still will have to use the old $var = load->view(TRUE) method anyway.

Actually, now that I think about it - why would someone just print out a view like "header.php"? That kind of seems sloppy to output HTML without proper, precise placement.
#56

[eluser]resolv_25[/eluser]
Hello.
I need multiple views from one controller, but in different manner.
I don't want multiple views to be appended together, but to have 2 separate views.
Is this possible?

To explain the problem, I need one report to be regular view in html,
the other will be downloaded as file.
These reports have a bunch of data, basically the same, but in different structure.


Code:
$this->load->view('obrada/repfile_view', $data);
$this->load->view('obrada/repstrA_view', $data);

So, this appends 2 views, is there some way to make these 2 views separate ?
File will be downloaded - this is fixed within the view, another will appear as regular report.
Thanks,
#57

[eluser]resolv_25[/eluser]
Well, actually will make this data written in file, and this will be downloaded from the view.
So, this is one solution.




Theme © iAndrew 2016 - Forum software by © MyBB