Implementing Pjax on a common header footer coding structure - php

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.

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

Related

Dynamic views with Codeigniter or templates or partial views

How can I load views of my nav menu without reloading the entire main view? something like templates or partial views. Is necesary to do this with ajax? How can it be? I donĀ“t know much about ajax. It will be possible to see an example?
I load my home view in controller like this:
$data = [
'header_view' => 'main/header',
'nav_view' => 'main/nav',
'section_view' => 'main/main_view',
'article_view' => 'main/article',
'aside_view' => 'main/aside',
'footer_view' => 'main/footer',
];
$this->load->view('home_view', $data);
Then I load the vievs from home view:
<section>
<?=$this->load->view($section_view);?>
</section>
...
And in the nav view I wanted to put the links to different sections without reload the nav view, because I will have a tree structure and other stuff.
why don't you use AngularJS ? you can make a single page application using ui-routes or ng-routes. you can make ajax call to your controller method that will render your view, and you can show that view in .
EDIT
In order to do a one page iframe site, you need to set up a controller to return a page without anything else
Controller -> loadpage($name)
then route it however you'd like
then, create an iframe with an id
<iframe name="maincontent"></iframe>
obviously, add in your needed styling / attributes.
On your links, add in targets
Link 1

How can i check if there is any content in them main page of joomla?

i am using joomla 3 for a web site, i don't use any content in the main page but the system output is on because i need to output contents on other pages of the site. the problem is i have a space in the middle of the page where normally the content comes. i know where this comes from but i have to disable it if there is no content on that selected page. i tried to check the
$this['template']->render('content')
which is actually used to render the specific content. but i was not able to use it in a conditional if. so i need to check if the loaded page has a content output. has anybody a idea how i could do that?
PS: i dont want do this with css.
You may check if you are showing the main page and render conditionally:
<?php
$app = JFactory::getApplication();
$menu = $app->getMenu();
if ($menu->getActive() == $menu->getDefault()) {
$this['template']->render('content');
}
?>
For multilingual site check this link for detecting if you are on the default page:
http://docs.joomla.org/How_to_determine_if_the_user_is_viewing_the_front_page
Just curious... why don't use the <jdoc:type="component/>?

Wordpress Get URL Footer File

I need to access the footer inside a wordpress theme via a url. Ideally it would just render the footer data and nothing else, alternative suggestions welcomed though.
To add some context, the data will be fetched through the url and a script will read the markup. This data will then be cached and available through Magento where it is needed to be displayed..
Is there a url path that will display it or should I make a new page that can be called via the base-url+the-page-name???
There's nothing built in to do that. You could use the AJAX API in your theme or a plugin and accomplish it.
You hook into an action that gets sent as a URL or POST data parameter and then make a request to yoursite.com/path/to/wordpress/wp-admin/admin-ajax.php.
<?php
add_action('wp_ajax_so20495429_display_footer', 'so20495429_display_footer');
add_action('wp_ajax_nopriv_so20495429_display_footer', 'so20495429_display_footer');
function so20495429_display_footer()
{
get_footer('ajax');
}
This will work for all users, logged in or not, despite the wp-admin URL. Here is code above wrapped up in a plugin.
what you can do is make a wordpress custom page template.
If you dont know how heres a little tutorial : http://www.expand2web.com/blog/custom-page-template-wordpress/
Now you want the custom page template to only load the footer (add the html, head and body opening tags yourself)
if you create a new page with your page template seletced it will only output the footer.
Hope you can get it to work
Greetings
merijn
What about $footer_url=get_template_directory_uri().'/footer.php'; ?

In Wordpress, how can I change the destinations of my links dependent on what page user is on?

I have the problem that I am using a theme where the navigation is simply 'scrolling' to a given part (eg. #contact) when pressed. However, I have implemented some seperate subpages that exits this scrollable page and thus renders the navigation ineffective.
My question is, how can I change the destination of my links or maybe change the menu entirely when users are on these subpages?
I should clarify that all the pages that need 'the new' navigation use a different page template called full_width.php. But since it is using an include header function I can't just replace the navigation.
Thank you for your time!
Here is simple solution based on templates.
if ( is_page_template('full_width.php') ) {
//menu for full width page
} else {
// Returns false when 'full_width.php' is not being used.
wp_nav_menu( $args );//read for args in codex to make menu you want.
}

Codeigniter session does not work after including Controller in view

I was working on a site in which on right side I am displaying some fixed type of dynamic content like event calendar, login, register etc. right side bar name is right_view.php
So first I was doing like this that I was sending parameters in every function of controller's and then in my view I was accessing right side parameters by calling right view like this
<?php $this->load->view('right_view');?>
then after login I can get my username that is stored in session.
After that I thought it is not a good approach to send parameters in every functions I just make a controller named right.php and in this controller I am passing parameters to right_view.php and after that in my view I changed my code for callig righr_view like this
<?php include(base_url().'right');?>
It display right content as I do above but one changed happen that I cannot access any of session stored variable in right side bar.
Is session does not work after including controller in view?
You're basically wanting to do a template system but going about it the wrong way. And for the record no I don't think you can (or at least should) be loading controllers into views like that.
What you want is a template file something like this:
<?php
$this->load->view('templates/header', $title);
$this->load->view('templates/sidebar',$sidebar_content);
$this->load->view('pages/'.$main_content);
$this->load->view('templates/footer');
?>
Call that template.php
Then in your controller you'd do something like this:
public function welcome()
{
$data['main_content'] = 'welcome';
$data['title']='Welcome to REfficient.com!';
$data['sidebar_content'] = 'sidebar/no_sidebar';
$data['additionalHeadInfo'] ='';
$this->load->view('templates/template',$data);
}
So if you look at the template file the first line is loading the header and including the title variable to insert into the page (header, sidebar, maincontent and footer are all their own separate PHP pages) and so on.
Now what I did (since my layout was very similar to yours) is my main sidebar file has an if statement that says if logged in show x, if not show login form.
Note - the additionalHeadInfo variable is so I can have includes like jQueryUI or something on an individual page without loading it on pages that don't need it.

Categories