Welcome Guest, Not a member yet? Register   Sign In
library issue
#1

[eluser]regal2157[/eluser]
Hey everyone,

I have a controller, and in the constructor, I call a library. I then try to use a method inside it, but I get thrown the error:

Quote:Fatal error: Call to undefined method stdClass::createLog() in /usr/apps/webdata/sandbox/application/controllers/admin.php on line 11

Here is my controller (part that calls the library, in the construct):
Code:
$this->load->library('Regal_log');
$this->Regal_log->log_file = 'login';
print_r(get_class_methods('Regal_log'));
//die();
$this->Regal_log->createLog(); //LINE 11
$this->Regal_log->Log('Login page loaded',1);

PHP does see the class methods, as the print_r returns:
Quote:Array ( [0] => __construct [1] => index [2] => createLog [3] => Log )

Any ideas?

I am totally lost on this one. :/ I can run the class outside of CI with not a problem..
#2

[eluser]Jaketoolson[/eluser]
Unless we're both over-looking the same thing, this should work!

Let's see Regal_log class, constructor, and createLog code.
#3

[eluser]regal2157[/eluser]
Code:
<?php

class Regal_log{
    function __construct()
    {
        //$CI =& get_instance();
    }
    
    function index(){}
    
    /**
     * Function createLog
     *
     * Create Log
     *
     */
    function createLog()
    {
        $this->files = $this->log_file.'.log';
        if(file_exists($this->files))
        {
            $this->Logging = fopen($this->files, "a");
        }
        else
        {
            $this->Logging = fopen($this->files, "w");
        }
    }

    /**
     * Function Log
     *
     * Creates a Log Entry
     *
     * @params User = UserID
     *         Message = Textual Message
     *         Verbosity = Level of Logging
     *
     */
    public function Log($Message, $Verbosity = NULL){    
        if($Verbosity == NULL){
            $Verbosity = 0;
        }
        $type = array(0 => 'SYSM', 1 => 'INFO', 2 => 'DEBUG', 3 => 'WARN', 4 => 'ERROR');
        
        $log_type = str_pad($type[$Verbosity], 7, ' ', STR_PAD_RIGHT);
        if($Verbosity != NULL && ($this->VerbosityLVL >= $Verbosity)){
            fwrite($this->Logging, date("n/j/Y H:i:s", time())." - ". $log_type .":: ". $Message."\n");
            return;
        }
        else{
            fwrite($this->Logging, date("n/j/Y H:i:s", time())." - ". $log_type .":: ". $Message."\n");
        }
    }
}
?>
#4

[eluser]danmontgomery[/eluser]
Code:
$this->regal_log
not
Code:
$this->Regal_log
#5

[eluser]regal2157[/eluser]
noctrum, you're a genious. all the hours... and I just had to change R to r..

thanks!




Theme © iAndrew 2016 - Forum software by © MyBB