[eluser]johnmerlino[/eluser]
Hey all,
when home/index page is loaded, this method is called:
Code:
public function index(){
$home = new Home();
$query_results = $home->find('all'); //I would rather use static method, like Home::find but if I define a static method in model, then I can't access $this property in it, therefore forgoing the built in active record pattern.
$defaults = array('head' => 'Welcome to HM Law Group', 'subhead' => 'The attorney who meets your expectations');
$result = array_merge($defaults,$query_results);
$this->template->render_content('template', '/homes/index', $result);
}
This method is called in model:
Code:
public function find($param){
if(is_null($param) || $param === 'all'){
$resources = $this->db->get('homes');
return $resources->result();
}
return null;
}
So result() returns an array of objects translated from field names. So I presume I can now access the property like $row->title.
I also have this autoloaded template class:
Code:
public function __get($name){
return isset($this->_data[$name]) ? $this->_data[$name] : NULL;
}
public function __set($name, $value){
$this->_data[$name] = $value;
}
function set($name, $value){
$this->template_data[$name] = $value;
}
function render_content($template = '', $view = '' , $data = array(), $return = FALSE){
$this->CI = get_instance();
$this->title = "Default Title";
$this->subtitle = "Default Subtitle";
$this->_data = array_merge($this->_data, $data);
$this->set('yield', $this->CI->load->view($view, $this->_data, TRUE));
$this->set('nav_list', array('Home', 'Photos', 'About', 'Contact'));
return $this->CI->load->view($template, $this->template_data, $return);
}
But when I try to access the objects in view, I get undefined variable:
Code:
<h1><?php echo $head; ?></h1>
<h2><?php echo $subhead; ?></h2>
<?php
foreach($_data as $row){
echo $row->title;
echo $row->description;
echo $row->link;
}
?>
alhough I am able to access $head and $subhead, which contained hard coded values declared in controller.
I am not sure how I can access my database results in view.
Thanks for response.