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

  • Home
  • SEARCH
  • 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

I have been working on JUNG2 for a while now, trying to visualize a
I have been looking into this a lot and people only mention the iOS
Is it possible to use .htaccess to protect an entire site, other than the
I'm just learning to use XCode and program in Objective-C (my plan is to
I have been playing with jstree (1.0rc2)+jquery (1.4.2) for the first time with c#.net
I've been using Git as a fat client for a Subversion repo, which has
I'm trying to programmatically verify that a jar file has not been obviously tampered
I have to create a game in flash for school. I'm kind of stuck,
When I was in college learning about web programming, they told us about Hibernate.
There are a few similar questions out there on SO (links at end), but

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.