0
votes

I am new to codeigniter ,

I want to redirect Login page request to this route

$route['login'] = 'TravelApi/login/';

So now http://localhost.com/codeigniter/login request should route through controller/TravelApi.php 's TravelApi class 's login() function.

Controller

public function login(){

        $contents['login_url'] = $this->googleplus->loginURL();
        $this->load->view('frontend/login',$contents);
}

My question is :

When request routes through above controller and then goes to frontend/login.php -- login.php file gets loaded but without header and footer.

But when I remove this route from config/routes.php

$route['login'] = 'TravelApi/login/';

then request does not route through controller and directly goes to frontend/login.php . and here it loads login.php file with header and footer.

But my need is to route from controller. and load view file with header footer.

So why it does not load header footer when routes through my controller's function ?

EDIT:

I found a function in default controller welcome.php

public function pages($alias=NULL)
{   
    $page='frontend/'.$alias;
    $this->load->view('frontend/common/head'); // For Head Scripts
    $this->load->view('frontend/common/header', $this->common_menu('TopMenu')); // For Header Content
    $this->load->view('frontend/common/menus', $this->common_menu('MainMenu')); // For Menus
    $this->load->view($page);  
    $this->load->view('frontend/common/footer'); // For Footer Content
    $this->load->view('frontend/common/foot'); // For Footer Scripts

}

But still not clear that why it does not load header footer when routes through my controller's function ?

1
is your header and footer file separated ? - shafiq.rst
yes this files are views/frontend/common/header.php .I just found that there is a function in core controller which loads header and footer. I am editing my question - Nirali Joshi

1 Answers

0
votes

You kind of answer your own question in your edit. The header and footer are located in seperate view files, and you need to load those too. So something like this should work:

public function login(){

    $contents['login_url'] = $this->googleplus->loginURL();
    $this->load->view('frontend/common/head'); // For Head Scripts
    $this->load->view('frontend/common/header', $this->common_menu('TopMenu')); // For Header Content
    $this->load->view('frontend/common/menus', $this->common_menu('MainMenu')); 

    $this->load->view('frontend/login',$contents);

// For Menus
    $page='frontend/'.$alias;
    $this->load->view($page);  
    $this->load->view('frontend/common/footer'); // For Footer Content
    $this->load->view('frontend/common/foot'); // For Footer Scripts
}

Note: The line $this->load->view($page); looks like it's probably the main content for the other page and here the main content should be $this->load->view('frontend/login',$contents);, if that's the case remove the $page view load.