Welcome Guest, Not a member yet? Register   Sign In
Is it possible to load a view on every page (Through the index?)
#1

[eluser]markanderson993[/eluser]
Hello, I hope this is a simple question.

Immediately when the index is loaded, I would like to display a header view at the top of the page. It would make sense to do this in the index.php page but that would be a terrible idea..

Basically how my site would work is..

1. You point your browser to mysite.com
2. A default header is loaded in immediately (note, this is not the default controller being loaded in, but a default header).

Is this possible?

Any help would be greatly appreciated, thanks!
Mark Anderson


EDIT* Actually what I believe I'm aiming for is a hook.. I'm looking into this right now
#2

[eluser]Jan_1[/eluser]
Not shure if I have understand you. So, how about that:
controller:
Code:
if (x=y) {$data['custom_header'] = 'header_2';}
$this->load->vars($data);
$this->load->view('template/page');
view(page.php):
Code:
$this->load->view($custom_header, true);
http://ellislab.com/codeigniter/user-gui...oader.html
#3

[eluser]Colin Williams[/eluser]
http://codeigniter.com/wiki/FAQ
#4

[eluser]markanderson993[/eluser]
Thank you for your quick responses, and I apologize for being cryptic in my description.

I am trying to convert my site to a facebook-like navigation system that works like this:
1. User goes to Facebook home page,
2. User navigates away to profile and browser url turns into facebook.com/#/username?...
3. User navigates away to inbox and browser url turns into facebook.com/#/username?rel=mail..
And each time the user navigates towards a new link, content is loaded in without a page refresh.

I understand how to make content load dynamically with mysite.com/#/.. changing in the url. My problem is, I essentially have 3 parts to my site.
1. Header - Must be displayed upon the FIRST initialization of the page (So it should not be initialized when another controller is processed)
2. Content - What will be changing
3. Footer - Again, must only be initialized ONCE and never called again.

So, when a user goes to a page this is what happens.
1. Navigate to www.mysite.com
2. Header is loaded
3. Content Box loads in default controller
4. Footer is loaded
5. User clicks on a link
6. A jQuery call is made to a controller's method to load content into the Content box (Notice, no header or footer was ever loaded)

Is this schema possible? I've tried using hooks, but they load each time controller's method is called which makes them useless because I'd like to just get the information from that method and not the header and footer also.

Any help would be greatly appreciated!!!

Thanks!
Mark Anderson
#5

[eluser]Colin Williams[/eluser]
Well, you get to decide what to serve with CodeIgniter. Could be a fully rendered interface, could just be a new chunk of HTML, could by JSON encoded data.

Sounds like you just want to check that the request is Ajax, and omit your header and footer for Ajax requests. Simple IF statement
#6

[eluser]markanderson993[/eluser]
Damn Mr. Williams. Damn. How do I go about doing that?! I like to think I'm pretty savvy with php headers and what not but what kind of code would i use to go about doing that?
#7

[eluser]Colin Williams[/eluser]
Code:
function is_ajax()
{
    return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest');

   // Or..
   return $this->input->server('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest';
}

(un)Surprisingly this can be found at http://codeigniter.com/wiki/FAQ/
#8

[eluser]markanderson993[/eluser]
I kinda just wanna give you hug now. Thank you so much for presenting such a simple solution.

So, I was thinking I could create a library class called serve with a function named view. Then, whenever I need to shell out a view, a first pass it through this "serve" class which identifies weather it is an ajax request or not and acts accordingly. Would this work?

Mark Anderson
#9

[eluser]Colin Williams[/eluser]
Sounds like you are just replacing the Loader::view() method. Not an approach I would take. It really depends on how your controller is building the interface.

My header and footer and similar loading calls would be in the Controller constructor, so I would just need to do the logic there.




Theme © iAndrew 2016 - Forum software by © MyBB