CodeIgniter Forums

Full Version: Development of a own library
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]mb2007[/eluser]
Hello,

I want to develop a own library and have some trouble. I put my library in the folder /aplication/libraries and I add my library to the autoload array. But when I call my library in a controller I get a Warning headers already sent. Why?

My Library:
Code:
class mbauthentification
{

    function mbauthentification()
    {
        log_message('debug', "Authentification Class Initialized");
        
        $this->CI=& get_instance();
        $this->CI->load->library('session');
        $this->CI->load->helper('form');
        $this->CI->load->helper('url');
    }

    function login()
    {
        $email = $_POST['email'];
        $this->CI->session->set_userdata('email', $email);
        return true;
    }
}

The Controller:
Code:
class User extends Controller {

     function User()
     {
         parent::Controller();
     }

     function login()
     {
        if($this->mbauthentification->login())
        {
            echo "TEST";
        }
     }
}

El Forum

[eluser]Michael Wales[/eluser]
Is there any white-space prior to your opening/closing PHP tags in the files you developed? That's usually the culprit.

El Forum

[eluser]mb2007[/eluser]
No there are no white-spaces. It's just:
Code:
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
...
?>

What's about the get_instance() problem with PHP 4. Could that be the problem?

El Forum

[eluser]mb2007[/eluser]
Ok. The problem is to add something to the session cookie:
Code:
$this->CI->session->set_userdata('email', $email);

I solved it, to add it not to the cookie, but to the database table ci_session.

El Forum

[eluser]Doosje[/eluser]
You probably had already some sort of output .. before you'd set the cookie.