unable to load custom library in CodeIgniter

141 views Asked by At

Here is my code for custom library

<?php 
  //$ci =& get_instance();


     class Menu extends CI_Controller{

      function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL){

            $this->load->view('includes/header', $headerInfo);
            $this->load->view($viewName, $pageInfo);
            $this->load->view('includes/footer', $footerInfo);
        }

  }

and in my controller, calling this loadViews like this

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/Menu.php';
class Login extends CI_Controller 
{  
    public function __construct() 
    {
        parent::__construct();
        //$this->load->database();
        $this->load->model('Login_model');
        $this->load->library('session');
        $this->load->library('menu');
    }
public function abc()
{
$this->menu->loadViews("staff_form", NULL, NULL, NULL);
}

What i have tried so for: load library in Autoload, create $CI instance and tried but nothing worked

1

There are 1 answers

0
Dum On BEST ANSWER

should be placed within your application/libraries/Menu.php

<?php 
class Menu{ //this is not a controller !

   $ci =& get_instance();

   function loadViews($viewName = "", $headerInfo = NULL, $pageInfo = NULL, $footerInfo = NULL){
      $ci->load->view('includes/header', $headerInfo);
      $ci->load->view($viewName, $pageInfo);
      $ci->load->view('includes/footer', $footerInfo);
   }
}
?>

May be, You have to take a look at Output class docs also.

However , I recommend loading views from your controller. This is a unwanted, extra work. You can create a function within the controller instead of creating a new library.