Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6084805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:33:57+00:00 2026-05-23T11:33:57+00:00

It’s been a while since I don’t use CI and I’m with a starter

  • 0

It’s been a while since I don’t use CI and I’m with a starter doubt.

EDIT:

class MY_Controller extends CI_Controller {

    public function __construct() {
        parent::__construct();
        if(!$this->session->userdata('usuario')) {
            $this->load->view('login');
        }
    }

}

class Home extends MY_Controller {

    public function __construct() {

        parent::__construct();
        Template::set('title', 'Login');
        Template::set('view', 'home');

    }

    public function index() {

        $this->load->view('template');

    }
}

What happens is that is the user session is invalid, it will load the login view but as in my Home controller contructor method is calling the view home, its loading both views on the same page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:33:57+00:00Added an answer on May 23, 2026 at 11:33 am

    Don’t put this in a hook, put it in MY_Controller in the __construct() method.

    http://codeigniter.com/user_guide/general/core_classes.html

    Example:

    // file application/core/MY_Controller.php
    class MY_Controller extends CI_Controller {
    
        function __construct()
        {
            parent::__construct();
            // your code here
        }
    
    }
    

    Just make sure that you extend MY_Controller instead of CI_Controller in the controllers you want to run this code in. If you have to change all of them, so be it.

    UPDATE: You could also try a post_controller_constructor

    post_controller_constructor

    Called immediately after your controller is instantiated, but prior to any method calls happening.

    But I would still prefer the MY_Controller method, as it is more flexible.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

it’s been a while since the last time I had to use regex, I
I don't really get lambda expressions. While they've been around since the days of
Its been a while since I had to do some Java/JSP... I have a
Its been a while since i have coded c++ and i have forgot an
It's been a while since I have used VBA on Excel. I want to
It's been a while since I have worked with ASP.Net and C#. I am
It's been a while since I last did Ruby programming -- looking at somebody
It's been a while since I've messed with .htaccess and I can't seem to
It's been a while since I've installed PHP for Windows, but every guide I've
It's been a while since I've created a new ASP.NET web application. (I've been

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.