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 4030604
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:29:34+00:00 2026-05-20T11:29:34+00:00

I am very, very new with MVC (just started yesterday) so this question is

  • 0

I am very, very new with MVC (just started yesterday) so this question is probably stupid, but I need to know how to check automatically if user is logged in on my functions that are in admin/user models.

I can put the checking in construct, this would help, but I have several models and maybe there is some even better way. I hope you will understand better what I want after you see my folder structure and code. Oh, and by the way – I use Code Igniter 2.0

Folders:

controllers/
../admin/
../../item.php
../../cat.php

Let’s see my item.php file…

<?php

class Item extends CI_Controller
{

    function Index()
    {

        //Checking if admin is logged in on every function is bad

        /* 
         * Is it possible to somehow make all admin functions go through
         * some kind of Admin class that will check automatically?
        */
        $isLogged = $this->session->userdata('is_logged_in');

        if ($isLogged == true)
        {
            $this->load->view('admin/item/main');
        }
        else
        {
            $this->load->view('admin/login');
        }
    }

    function Add()
    {
        $this->load->view('admin/item/add');
    }

    function Edit()
    {
        $this->load->view('admin/item/edit');
    }

    function Delete()
    {
        $this->load->view('admin/item/delete');
    }
}

I hope that this is easy question, thanks in advance 🙂

  • 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-20T11:29:34+00:00Added an answer on May 20, 2026 at 11:29 am

    I would implement the login-function in CI_Controller.
    Then I would set an protected variable in Item protected $loginRequired = true;.

    In function __construct() or Item() I would call parent::isLoginRequired($this->loginRequired) which checks if a login is required.

    I would also redirect to a specific login page with a parameter which redirects the user back to the page he needs to be logged in.

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

Sidebar

Related Questions

I'm very new to MVC (just 2 days in), but I'm wondering - is
I'm very new to MVC, and just building my first site, using NerdDinner as
I am still very new to the MVC framework, but I managed to create
I'm very new to ASP.NET MVC, so forgive me if this is something I
Very new to C++ and Cocos2d-x but I was just toying around with CCArray
Very new to FluentNHibernate, but I'm also excited about the area. I've recently started
i am very new to MongoDB and NoSQL in general and i've just started
I just started a new project, and now with ASP.NET MVC being designed in
I am still very new to routing with asp.net mvc, so perhaps this is
I am very new to Android application development. Just started Hello world android application

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.