I am trying to create my own library that will contain functions that will be available through the entire site. Inside /application/librariesI made a new file CustomFuncts:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class CommonFuncts extends CI_Controller {
protected $ci;
function __construct()
{
$this->ci =& get_instance();
}
public function verificaCookie(){
$this->ci->load->view('index');
}
}
And in the controller welcome.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index()
{
$this->load->library('commonFuncts');
$this->commonFuncts->verificaCookie();
}
}
I get the following error message:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Welcome::$commonFuncts
Filename: controllers/welcome.php
Line Number: 23
Fatal error: Call to a member function verificaCookie() on a non-object in
/var/www/vhosts/unikodf.com/httpdocs/application/controllers/welcome.php on line 23
I tried a lot of things, including extending the library CI_Controllerand using $this->load->view' instead of$ this-> ci -> load-> view ', but still I get the same message,
source
share