Jump to content

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 */

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.