Codeigniter click url with id to view page

Viewed 143

I try to get a variable working on my next page.

In controller.php I have the following:

        $buttons .= '<a href="'.base_url('klant/profiel/'.$value['id']).'" class="btn btn-default"><i class="fa fa-address-book"></i></a>'; 

And the part that is about the profiel view in controller I have this:

public function profiel($id = null) 
{
    $data = $this->klant_model->getKlantData($id);

    echo json_encode($data);

    $this->render_template('klant/profiel', $this->data);
}

In my model I have this:

public function getKlantData($id = null)
{
    if($id) {
        $sql = "SELECT * FROM klant WHERE id = ?";
        $query = $this->db->query($sql, array($id));
        return $query->row_array();
    }

    $sql = "SELECT * FROM klant";
    $query = $this->db->query($sql);
    return $query->result_array();
}

And in my view I have this:

 <?php echo $data['bedrijf']; ?>

I just want to echo out each colum of the row I have selected in the beginning.

This error I get:

Message: Undefined variable: value
1 Answers

This depends on how you have implemented $this->render_template inside your controller.

You want to pass in a variable called $value so you need to set that inside your $data.

public function profiel($id = null) 
{
    $data['value'] = $this->klant_model->getKlantData($id);

    $this->render_template('klant/profiel', $data);
}

So this will make $value accessible inside your view. Now if your array has an id column, then $value['id'] should now exist.

You should read the CodeIgniter documentation on how to pass values from a controller to a view.

Related