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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:17:09+00:00 2026-05-24T17:17:09+00:00

The problem: I’ve defined a few constants in my hook but I can’t access

  • 0

The problem:
I’ve defined a few constants in my hook but I can’t access them inside my sub-classed controller constructor.

The code:
A – the hook class:

class Settings extends CI_Hooks {

    public function load_settings() {
        $CI =& get_instance();
        $CI->load->model('hooks/settings_model');
        $data = $CI->settings_model->load_settings();
        define('MEMBERS_PER_PAGE', $data['members_per_page']);
        define('REGISTER_ENABLED', $data['register']);
        define('SITE_ACCESS_ENABLED', $data['site_access']);
        define('ADMIN_EMAIL', $data['admin_email']);
    }

}

B – the hook config:

$hook['post_controller_constructor'] = array(
                                'class'    => 'settings',
                                'function' => 'load_settings',
                                'filename' => 'settings.php',
                                'filepath' => 'hooks'
                                );

C – the controller

class MY_Controller extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        defined('SITE_ACCESS_ENABLED') ? print SITE_ACCESS_ENABLED : print "NULL";
    }
}

The way I understand *post_controller_constructor* is that it loads after the controller is initialized but before the constructor is executed. Apparently my defined constants don’t work in any constructor while constants from config/constants.php do work.

Any help and insights are greatly appreciated as hooks are totally new to me.

  • 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-24T17:17:10+00:00Added an answer on May 24, 2026 at 5:17 pm

    Well, post_controller_constructor happens just then. After the constructor has finished constructing the controller :-).

    You need to have it fire at pre_controller and manage the instantiation of the model on your own, or you will have to wait until the controller’s method is called before you can access the values. Sorry.

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

Sidebar

Related Questions

Problem: I can set the exposureMode property of AVCaptureDevice, but it does not stay
Problem: I have an address field from an Access database which has been converted
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem The form_for helper incorrectly determines the path to my nested resource inside of
Problem: Sometimes you will want to access a component from javascript with getElementById ,
Problem: Trying to create a Mix that is applied to the AVPlayerItem, but it
PROBLEM SOLVED. Special thanks to Andrew Noyes for explaining its not a class but
Problem: to combine PATHs with filenames, such that I can easily source many files.
Problem: I'm trying to load a stylesheet in Java but I get an error
Problem : I'm calling a SOAP Webservice, but need to change the URL with

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.