Welcome Guest, Not a member yet? Register   Sign In
Code Igniter: Access array elements from controller
#1

[eluser]justmelat[/eluser]
I have written this function in CI and for various reasons, I need to assign the contents of the array to variables to use later in the controller.

Because of the way this legacy code is set up, I need to get to the elements of the array from the controller. How do I get to the array elements in $data['oneResult'] from function below. I have tried a few things like the element() helper. Nothing works. In debug mode, I see the data I need and at this point, I need to assign so I want to do this:

Code:
$holdID = $data['oneResult']['contact_id'];
$holdLoc = $data['oneResult']['location'];  etc.


public function getOneValue(){
    $this->load->model('get_contents');
    $data['oneResult'] = $this->get_contents->getSpecificRow();
    $data['title'] = 'One Record - Contacts table view';
    $this->load->view('contacts_view', $data);
}

I am testing this in CI 2, but will need it to work in CI 1.7

Can anyone show me how to do this please?
#2

[eluser]sv3tli0[/eluser]
You may set something as..

Code:
public function getOneValue( & $data = array() ){
}
....
and you must call the function before next tasks..
Code:
$data = array();
$this->getOneValue($data);
$holdID = $data['oneResult']['contact_id'];
$holdLoc = $data['oneResult']['location'];




Theme © iAndrew 2016 - Forum software by © MyBB