-1

My Controller:

class Page extends CI_Controller {}

public function add()
{
    // $this->input->post('title')

    $models = $this->load->model('Page_Model', 'page');

    echo $models->page->insertData();
}

My Model:

class Page_model extends CI_Model {}

public function insertData()
{
    echo 'sdvsdf';
}

Error:

Fatal error: Call to a member function insertData() on a non-object in

I do not know what happened. Seems working correctly.

tereško
  • 58,060
  • 25
  • 98
  • 150
coreprojectz
  • 134
  • 1
  • 3
  • 12
  • I would argue that this is not a duplicate, because it is about a CI specific method. The post you mentioned uses typehinting which isn't in question here, and coreprojectz is trying to use the `model` method with a return value like is documented for the `view` method. – user20232359723568423357842364 Jul 09 '13 at 13:31
  • i already saw this article and i do not think i dublicated question. thanks – coreprojectz Jul 09 '13 at 15:37

1 Answers1

2

You should use $this->page->insertData(); to call the method.

The model method in the Loader class returns void.

See the comment, @return void in system/core/loader.php

/**
 * Model Loader
 *
 * This function lets users load and instantiate models.
 *
 * @param   string  the name of the class
 * @param   string  name for the model
 * @param   bool    database connection
 * @return  void
 */
public function model($model, $name = '', $db_conn = FALSE)
 ...