0

i am practicing CI framework on PHP when i get this error

Message: Undefined property: Test_controller::$testFunction

My Test_controller.php looks like this

class Test_controller extends CI_Controller {

public function test(){
    $this->load->model('Test_model');
    $test = $this->Test_model->testFunction;

    echo "Message : " . $test;
}

and my Test_model.php looks like this

class Test_model extends CI_Model{

public function testFunction(){
    return "This is a test function on model";
}

I can't find where i made a mistake.

Thanks for answering.

Virb
  • 1,639
  • 1
  • 16
  • 25
jeesoon
  • 377
  • 1
  • 3
  • 15

1 Answers1

2

In Test_controller

Add () in function testFunction

class Test_controller extends CI_Controller {

public function test(){
    $this->load->model('Test_model');
    $test = $this->Test_model->testFunction();

    echo "Message : " . $test;
}
Pradeep
  • 9,667
  • 13
  • 27
  • 34
  • Yes this was for testing only, im currently learning.That solve the problem... and that was embarrassing. – jeesoon Apr 17 '18 at 07:15
  • 1
    @jeesoon - you shouldn't echo from a controller, just generally speaking. It's ok for testing but ideally you would pass that data to the view and let it handle the formatting. – ArtisticPhoenix Apr 17 '18 at 07:16