Welcome Guest, Not a member yet? Register   Sign In
Config Item Not Working On Hooks
#1

(This post was last modified: 02-03-2016, 12:49 AM by wolfgang1983.)

Hello I am not sure what I have done wrong with my Hooks

On any other controller if I use $this->config->item('maintenance') or config_item('maintenance')

It returns the correct value 1 if maintenance mode on or 0 for off.

How ever when I try to load it into my hook with $this->CI->config->item('maintenance') or config_item('maintenance')

It does not work. Any suggestion on how to be able to use config item in hooks?

Hook


PHP Code:
<?php

class Preaction {

 
   public function __construct() {
 
       $this->CI =& get_instance();
 
   }

 
   public function check() {
 
       echo config_item('maintenance');

 
       //if (config_item('maintenance')) {
 
       //    echo "On";
 
      // } else  {
 
      //     echo "Off";
 
       //}
 
   }


PHP Code:
$hook['pre_controller'] = array(
 
       'class'    => 'Preaction',
 
       'function' => 'check',
 
       'filename' => 'Preaction.php',
 
       'filepath' => 'hooks'
); 
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#2

config_item() should work.

get_instance() can't work before a controller is instantiated.
Reply
#3

(02-03-2016, 02:27 AM)Narf Wrote: config_item() should work.

get_instance() can't work before a controller is instantiated.

When I use config_item('maintenance') it seems to only work with post_controller and not pre_controller
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply
#4

(02-03-2016, 02:32 AM)wolfgang1983 Wrote:
(02-03-2016, 02:27 AM)Narf Wrote: config_item() should work.

get_instance() can't work before a controller is instantiated.

When I use config_item('maintenance') it seems to only work with post_controller and not pre_controller

Something else is wrong, not config_item(). CI itself uses this function even before 'pre_system'.
Reply
#5

(02-03-2016, 02:35 AM)Narf Wrote:
(02-03-2016, 02:32 AM)wolfgang1983 Wrote:
(02-03-2016, 02:27 AM)Narf Wrote: config_item() should work.

get_instance() can't work before a controller is instantiated.

When I use config_item('maintenance') it seems to only work with post_controller and not pre_controller

Something else is wrong, not config_item(). CI itself uses this function even before 'pre_system'.

In stead of creating a library to set a config item. At the bottom of my config.php file I now do this

PHP Code:
require_once (BASEPATH 'database/DB.php');
$db =& DB();

$query $db->get('setting');

foreach (
$query->result_array() as $result) {
    
$config[$result['key']] = $result['value'];



And then when I use this config_item('maintenance') it now full works fine.
There's only one rule - please don't tell anyone to go and read the manual.  Sometimes the manual just SUCKS!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB