• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
& get_instance()

#1
Sad 
good morning riends...

I'm not going to work with CI Hook. I'm trying to import "= & get_instance ()" but to no avail. I'm using version 3.1.6.

What can it be?


<?php

class Login
{
    public $CI;
    
     public function __construct()
     {
            // Assign the CodeIgniter super-object
        $this->CI =& get_instance();
     }

    function validar()
    {
        echo "validar";
        $this->CI->load->helper('url');
    }


error:

A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: hooks/Login.php
Line Number: 16
Backtrace:
File: C:\xampp4\htdocs\crm-radiomar\application\hooks\Login.php
Line: 16
Function: _error_handler
File: C:\xampp4\htdocs\crm-radiomar\index.php
Line: 315
Function: require_once

Fatal error: Call to a member function helper() on null in C:\xampp4\htdocs\crm-radiomar\application\hooks\Login.php on line 16
A PHP Error was encountered
Severity: Error
Message: Call to a member function helper() on null
Filename: hooks/Login.php
Line Number: 16
Backtrace:


Thanks!
Tiago Cosme
Reply

#2
If your not going to use hooks then why is your Login.php Library in the hooks folder?

Also it depends on whats been loaded see Codeigniter.php and Loader.php in the ./system folder.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#3
(10-04-2017, 02:00 AM)InsiteFX Wrote: If your not going to use hooks then why is your Login.php Library in the hooks folder?

Also it depends on whats been loaded see Codeigniter.php and Loader.php in the ./system folder.

You can put your class in the Models directory or a subdirectory of Models. You will need to include it in your controller or in whichever model class is using the Login class.
Code:
defined('BASEPATH') OR exit('No direct script access allowed');
include_once(APPPATH.'models/Login.php');

class Login_controller extends CI_Controller {
...
Using composer you can store classes in a completely different directory, but the include_once is a simple way to start with non-singleton classes.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.