1

I am new to Codeigniter so I'm having some difficulties I want to retrieve data from the database and load it in the view but I couldn't figure out how. Here is my model:

public function viewClientWaterwell(){
    $userid = get_client()->userid;
    $waterwells = $this->db->select('*')
        ->from($this->table)
        ->where('ww_client_id', $userid)
        ->get()->result_array();
    return $waterwells;
}

Here is my clientController:

    public function viewClient()
{
    $data['waterwells'] = $this->waterwell_model->viewClientWaterwell();
    $this->data($data);
    $this->view('waterwells/clients/viewClient');
    $this->layout();
}

I want to pass some data in a view to the client side but I can't figure out how. I think there is some problem with my model but I cannot figure out what. I'm new to this and will appreciate your feedback. Thanks!

1 Answer 1

1

You just need to use second argument to pass data to your template or view file

Here is example to start

Inside your controller function

public function viewClient()
{
   $data = array( 'myvar' => 'I love stackoverflow' );
   $this->load->view('waterwells/clients/viewClient', $data);
}

And inside your template or view file you can access them by their name.

<?php echo $myvar; ?>

Sign up to request clarification or add additional context in comments.

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.