Jump to content

Archived

This topic is now archived and is closed to further replies.

unemployment

CodeIgniter - Fatal error: Call to a member function library() on a non-object

Recommended Posts

I'm not sure how to solve this codeigniter error.

 

Error: Fatal error: Call to a member function library() on a non-object.

 

Controller

 

public function index()
{
	$this->load->helper('url');

	$this->load->library('header');

	$data['title'] 			= $this->header->get_page_name();
	$data['gutter_value'] 	= $this->header->get_gutter_value();
	$data['js_page'] 		= $this->header->get_js_page_file();
	$data['page'] 			= $this->header->page;
	$data['index_page'] 	        = $this->header->index_page;
	$data['nav_names'] 		= $this->header->nav_names;
	$data['banner_img']		= $this->header->get_banner_img();

	$this->load->view('includes/header', $data);

	$this->load->view('about/about_view');

	$this->load->view('includes/footer');
}

 

Library File

 

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Header{

var $page 			= '';
var $index_page 	= '';
var $nav_names		= array();
var $banner_imgs 	= array();

public function __construct(){

	$this -> index_page = 'Writing';
	$this -> nav_names = array('Contact', 'About', 'Tools', 'Portfolio', 'Writing');

	if($_SERVER['PHP_SELF'] === '/index.php')
	{
		$this -> page = 'Writing';
	}
	else
	{
		$this -> page = end(explode(DIRECTORY_SEPARATOR, $_SERVER['PHP_SELF']));
	}
}

function get_page_name()
{
	$this->load->library('common');

	$page_names = $this->common->page_names();

	$title = (array_key_exists($this->page, $page_names) !== false) ? $page_names[$this->page]: '';

	if (array_key_exists($this->page, $page_names) !== false)
	{
		$title .= " | Jason Biondo";
	}

	return $title;
}

function get_banner_img()
{
	$banner_imgs = array('contact.jpg', 'about.jpg', 'tools.jpg', 'portfolio.jpg', 'writing.jpg');

	foreach($this->nav_names as $k => $name)
	{
		if(($this->page === strtolower($name)) OR ($this->uri->segment(1) === strtolower($name)))
		{
			$banner_img = $banner_imgs[$k];
		}
	}

	return isset($banner_img) ? $banner_img : 'writing.jpg';
}

function get_gutter_value()
{
	$gutter_values 	= array('304', '228', '158', '82', '0');

	foreach($this->nav_names as $k => $name)
	{
		if(($this->page === strtolower($name)) OR ($this->uri->segment(1) === strtolower($name)))
		{
			$g_value = $gutter_values[$k];
		}
	}

	return isset($g_value) ? $g_value : 0;
}

function get_js_page_file()
{
	$page = $this->page;

	if (file_exists("./js/pages/${page}.js"))
	{
		$javascript = "<script type=\"text/javascript\" src=\"./js/pages/${page}.js\"></script>";
	}

	return isset($javascript) ? $javascript : FALSE;
}
}
/* End of file header.php */ 
/* Location: ./application/libraries/header.php */

Share this post


Link to post
Share on other sites

I got this problem long ago and  this helped me . It may help you too

public function index()
{
$ci=&get_instance()
	$ci->load->helper('url');

	$ci->load->library('header');

}

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.