Welcome Guest, Not a member yet? Register   Sign In
question about views
#1

[eluser]Andres Gonzalez[/eluser]
Hi,

In the documentation about views is the following example excerpt:
Code:
$this->load->view('header');
$this->load->view('menu');
$this->load->view('content', $data);
$this->load->view('footer');

Using multiple calls like this to $this->load->view() appears to catenate the html files. If each individual html file has <html>, <title>, <body>, etc, tags, that is each html file is well formated, then you end up with a single file with multiple html sections.

Is this considered good form and programming practice?

Or should the individual pages only contain "sections" or incomplete html code so that the combined output page is one complete, well formated html page? The disadvantage to this approach would be that there is no way to use html syntax checkers on the individual pages because they are not really complete html pages.

Thanks,

-Andres
#2

[eluser]jedd[/eluser]
Hi Andres, and welcome to the CI forums.

You are correct - both with your assessment and your solution. The view files provide components or sections of the overall HTML output - so the first one would contain the HTML/DOCTYPE etc tags, and the last one would, presumably contain the /HTML tag.

I'm not sure what you mean by 'HTML Syntax checkers' - these are usually applied at the client side - such as the W3C validator - or do you mean something different?
#3

[eluser]Andres Gonzalez[/eluser]
Thanks for your response jedd.

Regarding a HTML syntax checker, I have run an HTML page thru a HTML checker just to verify that the HTML is correct. If I have a php script generate the HTML then I just run: php scr.php > check.html and then run check.html thru a HTML checker to make sure I have done everything correctly. So when I went thru the examples in the documentation, I first had full HTML pages for each section. When I looked at the source from the browser, I noticed several full HTML sections--the browser rendered it OK--it just look weird to me. So, then I tried only sections of HTML so the composite was well formed, and that, of course, worked well.

That feature seem really cool to me--it certainly simplifies maintaining headers and footers in pages.

I am not exactly sure if using a HTML checker is the proper way to do check things. I have only done that a couple of times when trying to debug a really hard problem.

-Andres
#4

[eluser]jedd[/eluser]
I don't use a checker, though I probably should.

I suspect that with this approach (separating out the generation of the full HTML page into sections) you could generate a very basic 'main content' component, and check your final output - this would be a way to ensure your header and footer sections were okay. After that you'd only have to worry about changes you were making to the bulk of your body.

You may want to look at the load->view options - the third parameter can be used (you set it to TRUE) to return, rather than display, the content of that view file. It may be possible to more easily produce the kind of output you need if you want to continue to run an html checker.
#5

[eluser]Andres Gonzalez[/eluser]
Thanks for your response.

Thats a good idea. I remember reading about the third parameter to load->view and now I know a good use for it--I will try it out.

-Andres




Theme © iAndrew 2016 - Forum software by © MyBB