Reputation: 529
im using codeigntier framework im trying to solve a problem to do with retrieving information from a database for example:
model.php:
public function read(){
$query = $this->db->get('table');
return $query->result();
}
controller.php:
public function doSomething () {
$exampleArray['name'] = "Bob's Database";
$getModel = $this->load->model('model','getData');
$modelData = $this->getData->read();
// i want to assign the the $modelData to a array element like so
$exampleArray['modelData'] = $modelData // here's where im stuck :(
}
thanks for your help!! p.s. this is not an error, its just a question :)
}
Upvotes: 1
Views: 56
Reputation: 7040
If you want to be able to access $exampleArray
outside of that method, you'll have to do one of two things:
a) set it as a class variable
class MyClass {
public $exampleArray;
.
.
.
}
then refer to it using
$this->exampleArray['index']
or b) pass it by reference into your doSomething()
function:
public function doSomething(&$exampleArray) { ... }
The php manual has a section on variable scope that should help you better understand this.
Upvotes: 2