Welcome Guest, Not a member yet? Register   Sign In
Undefined Index
#1

Hi Everyone,

I am new to Codeigniter and am working on my first project and am getting an Undefined Index error and am not sure why. I have been modeling my code after the News example on the Codeigniter website.

My code is posted below, but it seems that the following line in my controller is not passing the $id to the query in the model, because anytime I try to reference the output of this query (e.g. $data['title'] = $data['family']['familyName']) I get:
Quote:Message: Undefined index: familyName
.
PHP Code:
$data['family'] = $this->heart_model->get_families($id); 


My model is:

PHP Code:
<?php
class Heart_model extends CI_Model {

    public function 
__construct()
    {
        
$this->load->database();
    }
    
    public function 
get_families($id FALSE)
    {
            
$this->db->order_by('familyName''ASC');
            
$query $this->db->get('families');
            return 
$query->result_array();
    } 


My Controller is:

PHP Code:
<?php
class Heart extends CI_Controller {
    
    public function 
__construct()
    {
        
parent::__construct();
        
$this->load->model('heart_model');
        
$this->load->helper('url_helper');
    }
    
    public function 
index()
    {
        
$data['heart'] = $this->heart_model->get_families();
        
$data['title'] = 'Heritage Heart';

        
$this->load->view('templates/header'$data);
        
$this->load->view('heart/index'$data);
        
$this->load->view('templates/footer');
    }
    
    public function 
view($id NULL)
    {
        
$data['family'] = $this->heart_model->get_families($id);
            
        if (empty(
$data['family']))
        {
            
show_404();
        }
        
        
$data['title'] = $data['family']['familyName'];
        
        
$this->load->view('templates/header'$data);
        
$this->load->view('heart/view'$data);
        
$this->load->view('templates/footer');
    } 

I appreciate any help. Also, any advice on how I can troubleshoot these types of problems on my own would be appreciated. Thanks!
Reply


Messages In This Thread
Undefined Index - by mpar612 - 12-28-2015, 08:24 PM
RE: Undefined Index - by dhinakar - 12-28-2015, 09:44 PM
RE: Undefined Index - by pdthinh - 12-28-2015, 10:02 PM
RE: Undefined Index - by mpar612 - 12-29-2015, 06:06 PM
RE: Undefined Index - by pdthinh - 12-29-2015, 06:21 PM



Theme © iAndrew 2016 - Forum software by © MyBB