Welcome Guest, Not a member yet? Register   Sign In
Views
#1

[eluser]Moon 111[/eluser]
How can I setup my views so that I don't have to write the code for my HTML template in every file?

Also, where do I put my stylesheets, javascript files etc.?

Thank you very much for the help. I've been able to jump-start CI very quickly...

- Moshe
#2

[eluser]llbbl[/eluser]
you can include common headers and footers by loading other view files within a view.

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

You can put your css and js wherever you want to. Some people put them in public /public/css/main.css or directly in the web root /js/jquery.js
#3

[eluser]Moon 111[/eluser]
Hmm... Your solution is setting off all my alarm bells, but I suppose in this case it's neccesary to duplicate the code. I guess if I had, like, 1000 views that needed to be changed, I could just cheat and write some code to do it automaticly Smile.
#4

[eluser]llbbl[/eluser]
there is nothing wrong with it. if your so concerned about direct access change 'inc' to 'supersecretblahblahneverguessfoldername'.

the full path is.
/system/application/views/inc/header.html

if your using CI everyone knows where your views and controllers reside.

/system/application/views/welcome_message.php

When you try to load a view directly by url (/system/application/views/foobar.php) with a common header you will get a fatal error.
Fatal error: Using $this when not in object context

Otherwise the file will look like a blank page without any data in it. All your <?php echo $whatever; ?> won't show up in the html.

Its actually very helpful if you have a site with more than 5 pages that have similar header or footer.
#5

[eluser]Moon 111[/eluser]
No, what I mean is that you have to copy that code snippet to all your views and it could be a pain if you needed to change the code.
#6

[eluser]llbbl[/eluser]
The point is to make it simpler to make small changes. You make changes to header.html or footer.html and it affects all your pages.

If you already have 1000 views without a common header or footer your going to have to go through and edit them. I would suggest manually because it will take time to write a automated process and it likely to have bugs. It is usually quicker and more accurate to do it by hand.

cntrl+v for the win.

next time make sure to include the common files while you are developing.
#7

[eluser]Moon 111[/eluser]
No... If after you added that common code you needed to change it it would be a pain.
#8

[eluser]llbbl[/eluser]
Now THAT just doesn't make any sense, its totally easier this way.

Why would you change header files (header2.html) instead of making changes to it? There is no GOOD reason you would ever need to do this.

If your concerned about testing your changes before you make them, well you should be using a subdomain (possibly on a different machine if the site is large enough) for testing!




Theme © iAndrew 2016 - Forum software by © MyBB