unemployment Posted November 7, 2011 Share Posted November 7, 2011 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 */ Quote Link to comment https://forums.phpfreaks.com/topic/250592-codeigniter-fatal-error-call-to-a-member-function-library-on-a-non-object/ Share on other sites More sharing options...
samitrimal Posted November 9, 2011 Share Posted November 9, 2011 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'); } Quote Link to comment https://forums.phpfreaks.com/topic/250592-codeigniter-fatal-error-call-to-a-member-function-library-on-a-non-object/#findComment-1286653 Share on other sites More sharing options...
unemployment Posted November 10, 2011 Author Share Posted November 10, 2011 yeah, that was the issue. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/250592-codeigniter-fatal-error-call-to-a-member-function-library-on-a-non-object/#findComment-1287038 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.