David
David

Reputation: 10625

Getting and using returned variables from a Method to a Controller in CodeIgniter

I currently have a model that creates an array and returns it using the following:

$data = array(
    'title' => $this->input->post('title'),
    'slug' => $slug,
    'text' => $this->input->post('text')
);

$this->db->insert('table-name', $data);
$id = $this->db->insert_id();

return $data;

Unfortunately the variable $data is empty when I get it back in my controller. How do I go about getting hold of this data to pass to my view.

Upvotes: 0

Views: 46

Answers (1)

Shomz
Shomz

Reputation: 37701

The code seems fine.

Controller:

$data['mydata'] = $this->my_model->my_method();
$this->load->view('my_view', $data);

View

<?= $mydata ?>

Upvotes: 1

Related Questions