Can anyone see a bug in this constructor? I'm able to print $this->$model in method __construct(), but it is not available elsewhere within the same object and I am pulling my hair out. I've used this technique before without problems, and it is in fact working in other parts of my app.
Code: Select all
private $uses = array('broker', 'location');
public function __construct($method = 'index')
{
global $view;
$this->view =& $view;
global $registry;
$this->registry = $registry;
parent::__construct();
if (!router::isAlias($method)) {
$this->{$method}();
} else {
$method = router::connect($method);
$this->{$method}();
}
if (ine($this->uses)) { // isset and not empty
foreach ($this->uses as $model) {
$this->{$model} = new $model();
if(!$this->$model instanceof $model) {
throw new Exception("Model \"$model\" not found in ". __METHOD__);
} else {
pr(($this->$model)); // is print_r'd correctly
}
}
}
}
public function edit()
{
if (!isset($this->data)) {
// this is a bug workaround
$this->location = new location(); // shouldn't need to do this
// get a list of locations
$this->location->get();
$this->view->set('locations', $this->registry->data['location']);
} else {
// another bug workaround
pr(($this->broker)); // undefined property $broker
$this->broker->get();
$this->view->set('broker', $this->registry->data['broker']['organization']);
$this->view->set('location', $this->registry->data['location']['name']);
}
$this->view->render('contacts');
}
Thanks in advance