Question

I'm using Codeigniter and the Ionauth library to manage users. The structure I'm using is as follows:

Controllers:
- home
- auth

Views:
- home
  - home_view.php

- templates
  - header.php
  - footer.php

- auth
  - login
  - register

When I create my home view, it adds the header.php and footer.php templates and passes it's own data into the main body.

My issue is, I'd like to use my login function within the header.php file (within a form), however, this isn't currently possible because my login function is situated in the /auth/ controller. Would it be possible for me to use this login function outside of the /auth/ controller, I.e. in the header.php file within the /templates/ folder?

If not, are there any possible solutions you can propose?

Thanks

Was it helpful?

Solution

Yes you can do like this-

Extend your core ci_controller to MY_Controller

So, create your file - application/libraries/MY_Controller.php - and fill it with this code:

<?php

class  MY_Controller  extends  Controller  {

    function MY_Controller ()  {


__construct()
{
parent::Controller();

$this->load->view('templates/header')  // now in this way your header will get automatically included to every controller which extends MY_Controller

}
    }
//...
}
?>

Now extend your controllers to MY_Controller

class  auth extends  MY_Controller  {
    function  __construct()  {
        parent::MY_Controller();
    }
//...
}

class  home extends  MY_Controller  {
    function  __construct()  {
        parent::MY_Controller();
    }
//...
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top