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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:59:06+00:00 2026-05-27T12:59:06+00:00

I am using Codeigniter to build my project. Here i have some doubts or

  • 0

I am using Codeigniter to build my project.

Here i have some doubts or need some clarification.

Can i use Constructors to do somethings that which affect all other functions in codeigniter/php ??

Please take a look here :

<?php
class New extends CI_Controller
{
 function __construct()

{

//Constructor codes...

}
 function Create_page()  //The user need to be Logged in to perform this
{
 //Checking whether the user logged in or not if yes allowed else denied. 
}
 function Edit_page()      //The user need to be Logged in to perform this
{
 //Checking whether the user logged in or not if yes allowed else denied.
}
function Delete_page()  //The user need to be Logged in to perform this
{
 //Checking whether the user logged in or not if yes allowed else denied.
}
function about_us()   //This is a public action no need to Log in 
{
   // this is a pulic action ,no need to check the login status
}
}
?> 

As you can see that i need to check the Logged in status on each Private functions ,

Is there any way that i can do this on constructor ? so that constructor will check logged in or not ….but it will only need to affect some Functions…

  • 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-27T12:59:07+00:00Added an answer on May 27, 2026 at 12:59 pm

    Call a function in constructor, which checks following steps:

    • define which methods needs login, which do not.
    • detect the current method call.
    • if required, then do login, else not.

    <?php
    class New extends CI_Controller
    {
    
      var $publicMethods  = array("aboutUs"); 
    
     function __construct()
    
    {
    
    //Constructor codes...
      $this->_validateLogin();
    
    }
    
     function _validateLogin()
     {
        $router = &load_class('Router');
        $currentMethod = $router->fetch_method();
        if(in_array($currentMethod,$this->publicMethods) == false){
           // call some login functionality
        }
      }
    
     function Create_page()  //The user need to be Logged in to perform this
    {
     //Checking whether the user logged in or not if yes allowed else denied. 
    }
     function Edit_page()      //The user need to be Logged in to perform this
    {
     //Checking whether the user logged in or not if yes allowed else denied.
    }
    function Delete_page()  //The user need to be Logged in to perform this
    {
     //Checking whether the user logged in or not if yes allowed else denied.
    }
    function about_us()   //This is a public action no need to Log in 
    {
       // this is a pulic action ,no need to check the login status
    }
    }
    ?> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Kind sirs, I'm using Codeigniter to build a blog. I might need a way
I'm using CodeIgniter (a PHP framework) to build an app, and I have an
I want to build a project using codeigniter, the project consist of 2 levels,
Issue/Question : I'm using CodeIgniter to build an event calendar, and I have included
I have a project that I am developing built off CodeIgniter. The main part
I'v built a application using codeigniter and I have a message system that displays
I have one project that is using ESAPI4PHP which is a port of OWASP's
The website is build with Codeigniter MVC framework. I have a page that is
I'm trying to build a multi-app site using CodeIgniter. The individual applications need to
I'm using CodeIgniter to build my first web app. For demo purposes, users can

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.