-3

i am currently working on a project in codeigniter. I want to separate my controllers for each function.

Example,

controller_for_login.php
controller_for_redirecting_to_other_views.php
controller_for_CRUD.php
controller_for_others.php

is there any way to make it like this one? so that my codes will be a lot organized. thanks.

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
kev_m
  • 325
  • 7
  • 30

1 Answers1

0

Its very easy

1)First create a new file in controller folder e.g Classname.php

2)Edit that file

class Classname Extends CI_Controller
{
}

3) Put your new functions inside this class file

Put the class file into library folder the file like this

class Authenticate {

    public function __construct()
    {
        $this->ci =& get_instance();

    }
  public function is_logged_in()
    {
        $sessionid = $this->ci->session->userdata('moderId');
        if($sessionid)
        {
        return isset($sessionid);
        }
         else if(!$sessionid) {
      redirect(base_url() . 'moderator');
 }
    }
}

And in the controller file, call that class function like this

class B2bcategory extends CI_Controller {    
    function __construct() {
        parent::__construct();
        $this->authenticate->is_logged_in();
    }
}
mega6382
  • 9,211
  • 17
  • 48
  • 69
Angel
  • 614
  • 6
  • 24
  • i have already do it. the problem is, i cannot call another class from another controller. – kev_m Feb 05 '16 at 05:53
  • create that class in library folder. and call it in your controller $this->authenticate->is_logged_in(); – Angel Feb 05 '16 at 06:48
  • hi kev_m, please put the class file into library folder,am edited my answer,check it – Angel Feb 05 '16 at 18:15