Codeigniter 3 MY_Controller not found

1

The error is as follows, by extending the Register class of the MY_Controller to create the user login, it throws me the following error. Any ideas?

He says he has not found the class, but even adding it does not find it.

Driver for registration in .php

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

class Register extends MY_Controller
{

    public function index()
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('first_name', 'First name','trim|required');
        $this->form_validation->set_rules('last_name', 'Last name','trim|required');
        $this->form_validation->set_rules('username','Username','trim|required|is_unique[users.username]');
        $this->form_validation->set_rules('email','Email','trim|valid_email|required');
        $this->form_validation->set_rules('password','Password','trim|min_length[8]|max_length[20]|required');
        $this->form_validation->set_rules('confirm_password','Confirm password','trim|matches[password]|required');

        //En caso de que no pueda registrarse correctamente lo redirecciona al index de nuevo
        if($this->form_validation->run()===FALSE)
        {
            $this->load->helper('form');
            $this->render('register/index_view');
        }
        else
        {
            $first_name = $this->input->post('first_name');
            $last_name = $this->input->post('last_name');
            $username = $this->input->post('username');
            $email = $this->input->post('email');
            $password = $this->input->post('password');

            $additional_data = array(
                'first_name' => $first_name,
                'last_name' => $last_name
            );

            $this->load->library('ion_auth');
            if($this->ion_auth->register($username,$password,$email,$additional_data))
            {
                $_SESSION['auth_message'] = 'The account has been created. You may now login.';
                $this->session->mark_as_flash('auth_message');
                redirect('user/login');
            }
            else
            {
                $_SESSION['auth_message'] = $this->ion_auth->errors();
                $this->session->mark_as_flash('auth_message');
                redirect('register');
            }
        }
    }
} 
    
asked by Jose 27.04.2017 в 12:26
source

1 answer

3

The MY_Controller.php driver should be located in application / core / MY_Controller.php and extend the CI_Controller class.

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

class MY_Controller extends CI_Controller {

    public function __construct()
    {
        parent::__construct();
    }
}

Additionally in the application / config / config.php file you should have configured the suffix to be used for the classes that extend the core.

$config['subclass_prefix'] = 'MY_';

The CodeIgniter documentation details how to extend the base classes link

    
answered by 27.04.2017 / 16:20
source