A
A
Artyom2016-10-04 17:42:40
CodeIgniter
Artyom, 2016-10-04 17:42:40

CodeIgniter: How to correctly pass an array from Model to View via Controller?

CodeIgniter: How to correctly pass an array from Model to View via Controller?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2016-10-04
@springimport

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

class Mymodel extends CI_Model
{

    public function myFunction()
    {
        $data = [
            'element1' => 'Test',
            'element2' => '123'
        ];
        
        return $data;
    }
}

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

class Mycontroller extends CI_Controller
{

    public function index()
    {
        $this->load->model('mymodel');
        
        $data = $this->mymodel->myFunction();
        
        $this->load->view('my_view', [
            'data' => $data,
        ]);
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question