unable to display query results in a view codeigniter

前端 未结 2 1343
臣服心动
臣服心动 2021-01-22 16:47

I\'m trying to show the results from my database in a dynamic table, I\'m using codeigniter:

This is my model:

class Cliente_model extends CI_Model {

fu         


        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 17:34

    If you call a view with a data array, the provided array needs to be an associative array, that uses the variable names as keys and its values as the variable values. Example:

    //Controller
    $data = [];
    $data['var1'] = true;
    $data['var2'] = 'This is a string value';
    $this->load->view('cliente_view',$data);
    

    Now, you are able to call the variables $var1 and $var2 in your view, because the are keys in the data array

    //View
    if ($var1)
        echo $var2;
    else
        echo 'false';
    

    So the solution for your problem is to add the variable name 'data' as a key to your provided array:

    $data = ['data' => $data];
    $this->load->view('cliente_view',$data);
    

    After that you can use the variable $data in your view.

提交回复
热议问题