codeigniter passing array data from model to controller

前端 未结 1 775
春和景丽
春和景丽 2020-12-17 05:29

I\'m executing the following query in the get_distribuidor() function of my model:

public function get_distribuidor()
{
    $this->load->helper(\'url\'         


        
相关标签:
1条回答
  • 2020-12-17 06:05
    $teste=$this->fichas_model->get_distribuidor();
    $this->load->view('produtos/ponto1',$data, $teste);
    

    should be:

    $data['teste'] = $this->fichas_model->get_distribuidor();
    $this->load->view('produtos/ponto1',$data);
    

    The 3rd parameter for view() is used if you want to grab the content of view() into a variable. To pass data to the view you need to add it as an array item of $data.

    For Example:

    $data = array(
        'title' => 'My Title',
        'heading' => 'My Heading',
        'message' => 'My Message'
    );
    
    $this->load->view('blogview', $data);
    // You then access $title, $heading, $message in the view file
    

    What you are doing with above edit is the following essentially:

    $data = array(
        'teste' => $this->fichas_model->get_distribuidor()
    );
    
    $this->load->view('produtos/ponto1', $data);
    // You then access $teste in the view file, 
    // which will be an array so you can access $teste['morada']
    
    0 讨论(0)
提交回复
热议问题