Frage

I am developing a project using codeigniter that has common header and footer. By using pjax I am able to dynamically change the content alone without disturbing the header and the footer. Also the url changes with respect to the controller. Below is my concern over the url and SEO analogy.

My default home page controller loads the header, index page and the footer as shown below.

public function index(){
    $this->load->model('dbmodel');
    $data['about'] = $this->dbmodel->about();
    $this->load->view('templates/header',$data);
    $this->load->view('includes/index',$data);
    $this->load->view('templates/footer');
}

Suppose I click on a menu item, it loads the corresonding controller path in the url (say - http://domain.com/main/bandDirectory) and the pjax content div alone is replaced/updated with the content while header and footer remaining the same.

public function bandDirectory(){
    $this->load->model('dbmodel');
    $data['content'] = $this->dbmodel->band();
    $this->load->view('includes/bandDirectory',$data);
}

This works fine when the menu items are navigated from the home page as it loads the header and footer initially. But what if we directly hit the url (say http://domain.com/main/bandDirectory). This controller does not contain header and footer and it loads only the content which breaks the page apart! This would become a serious issue if search engines indexes these urls. How to overcome this issue?

P.S : Since I am implementing a player in the header, I do not want to include header and footer in all the controllers as this would stop the player from playing when header refreshes.

War es hilfreich?

Lösung

What I did in our project was that to look for pjax header in the request, if the pjax header is present then load the content template only else load the full template, this is my corresponding code in perl, hope it helps

sub tour {
my $self = shift;
return $self->render(
    template => 'static/tour',
    layout   => $self->req->headers->header('X-PJAX') ? 'content_header' : 'full_width',
);}

you can implement the same in php

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top