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

class MY_Controller extends CI_Controller
{
    protected $rtn = ['ok' => true, 'msg' => ''];
    protected $classes = [];

    /**
     * MY_Controller constructor.
     */
    public function __construct()
    {
        parent::__construct();
        // var_dump(get_cookie('bs_admin'));die;
        if (!get_cookie('bs_admin')) {
            redirect('/');
        }
        // $this->load->database();
    }

    public function getPage($func_name)
    {
        return strtolower(get_class($this)) . DIRECTORY_SEPARATOR . strtolower($func_name);
    }

    protected function &getClass($package, $class, $args = array())
    {
        if (empty($this->classes[$package . $class]))
            $this->classes[$package . $class] = $this->classloader->load($package, $class, $args);
        return $this->classes[$package . $class];
    }

    protected function response($body)
    {
        $this->output
            ->set_status_header(200)
            ->set_content_type('application/json')
            ->set_output(json_encode($body));
    }
}
