-1

I'm completely new to PHP and CodeIgniter and I'm trying to create a link in a view that, when clicked will return a list of data from a specific category.

vgs_model.php model

public function pcList(){

    $this->db->select('*');
    $this->db->from('videogame');
    $this->db->where('Format', 'PC');
    $query = $this->db->get();

    return $query->result();

}

search.php controller

public function __construct()
{
    parent::__construct();

    $this->load->helper('form');
    $this->load->helper('url');      
    $this->load->model('vgs_model');

}

public function index()
{
    $this->load->view('header_view');
    $this->load->view('search_view');
    $this->load->view('footer_view');
}

public function getPc(){

    $search_term = 'PC';

    $data['results'] = $this->Vgs_model->pcList();
    $this->load->view('search_results', $data);

}

search_view View

<a href = <?php echo site_url('Hello/getPc'); ?>>View PC Games</a>

I've been getting the following error

Message: Undefined property: Search::$Vgs_model

Filename: controllers/search.php

Line Number: 40

Line 40 is this $data['results'] = $this->Vgs_model->pcList();

What am I doing wrong? Any help would be appreciated.

Thanks for reading my post.

tereško
  • 58,060
  • 25
  • 98
  • 150
Greg Chapman
  • 49
  • 1
  • 1
  • 4

1 Answers1

1

That sould be in lowercase:

 $data['results'] = $this->vgs_model->pcList();
egig
  • 4,370
  • 5
  • 29
  • 50
  • Oh my god that is hilarious! Such a simple mistake. I love programming with a text editor. Thank you so much Charlie. – Greg Chapman May 03 '13 at 02:01
  • yeah, I do programming with text editor too, glad can help :) – egig May 03 '13 at 02:04
  • Actually according to the CI conventions your model loading should be `$this->load->model('Vgs_model');` where the model name is capitalized. The above would then be kept capitalized unless you specify the 2nd parameter when loading to name it differently. See http://ellislab.com/codeigniter/user-guide/general/models.html but that's just sticking to the way CI does it, which you should be using since it can have unintended side effects in latter releases. – kittycat May 03 '13 at 09:08
  • Let's talk about should: That should not be an answer ;) – hakre May 03 '13 at 12:22
  • @hakre that should be wrong answer, I dont know anything yet about CI conventions, what is that? where to find them? – egig May 03 '13 at 12:36
  • I was not commenting because of "wrong answer" but in the meaning that you could leave a comment instead IMHO and it should be sufficient and more useful for this website here. – hakre May 03 '13 at 12:39
  • mmm... I just read 'What am I doing wrong?' in the question, and I just answering 'That sould be...' – egig May 03 '13 at 12:42