0

I can't access codeigniter controller array values in the view. where did i miss.

mymodel

function get_data(){        
    $this->db->select('prod_id, content, details');
    $query = $this->db->get('tblesample');        
    return $query->result();   
}

controller

public function index(){
    $this->load->model('mymodel'); 
    $user_info = $this->mymodel->get_data();

    $this->load->view('inc/header_view');
    $this->load->view('data_view', $user_info);        
}

data_view

<div class="col-md-9">
    <?php
        foreach ($user_info as $info) {
            echo $info->content;
        } 
    ?> 
</div>

3 Answers 3

3

In controller change the code.

public function index(){
    $this->load->model('mymodel'); 
    $data['user_info'] = $this->mymodel->get_data();

    $this->load->view('inc/header_view');
    $this->load->view('data_view', $data);        
}
Sign up to request clarification or add additional context in comments.

Comments

2

You be better off using associative array to pass on to the view:

public function index(){
    $this->load->model('mymodel'); 
    $data = [
        'user_info' => $this->mymodel->get_data(),
    ];

    $this->load->view('inc/header_view');
    $this->load->view('data_view', $data);        
}

And reference it like $user_info in your view.

Comments

2

You are not passing the array correctly to view . Pass your data like this

    public function index(){
    $this->load->model('mymodel'); 
    $user_info['user_info'] = $this->mymodel->get_data();
    $this->load->view('inc/header_view');
    $this->load->view('data_view', $user_info);         
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.