1

I'am trying call custom library function witch should return inputed values back to form, but I'am geting error. enter image description here

Controler:

<?php

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

class Guest extends CI_Controller {

public function __construct(){
    parent::__construct();
    error_reporting(E_ALL ^ (E_NOTICE));
    $this->load->helper(array('form', 'url', 'date'));
    $this->load->library('form_validation', 'uri');
    $this->load->model('dayData');
    $this->load->library('session');
    $this->load->library('guest');
}

public function index(){        
    $this->login();
}

public function dataToView($data, $viewFile){
    $this->load->view('template/header');
    if($viewFile != ''){
        $this->load->view('user/' . $viewFile, $data);
    }
    $this->load->view('template/footer');
}

public function login(){
    $this->dataToView($data, 'guest/login');
}

public function registration(){
    if($this->input->post('registrationSubmit') !== null) {

        //$this->form_validation->set_error_delimiters('<div class="alert alert-warning" role="alert">', '</div>');
        $this->config->load('form_validation');
        $this->form_validation->set_rules($this->config->item('registrationValidation'));

        if($this->form_validation->run() == FALSE){
            var_dump($this->guest->registrationPost());
            $this->dataToView($data, 'guest/registration');
        } else {
            echo "string";
        }
    } else {
        $this->dataToView($data, 'guest/registration');
    }
}

}

Library:

<?php

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

class Guest {

protected $CI;

public function __construct(){
    // Assign the CodeIgniter super-object
    $this->CI =& get_instance();
    //$this->CI->load->model('Guest');
    $this->CI->lang->load('error', 'english');

}

public function registrationPost(){
    $result = array('name' => $this->CI->input->post('name'),
                    'nickName' => $this->CI->input->post('nickName'),
                    'email' => $this->CI->input->post('email'));
    return $result;
}

}
  • releated http://stackoverflow.com/questions/54566/call-to-a-member-function-on-a-non-object – Linus Jan 03 '16 at 19:48

2 Answers2

0

There is a naming conflict between the controller and the custom class. They should not have the same name.

DFriend
  • 8,869
  • 1
  • 13
  • 26
0

You have duplicate class names. The controller class name is Guest and the library class name is also Guest.

When CodeIgniter goes to load the Guest library, it will skip over it and log a debug message. https://github.com/bcit-ci/CodeIgniter/blob/develop/system/core/Loader.php#L1032

I suggest renaming your library to something else, Registration perhaps?

Chad Lad
  • 464
  • 5
  • 7