-1
我完全不熟悉PHP和CodeIgniter,我试图在视图中创建一个链接,点击后将返回一个特定类别的数据列表。CodeIgniter链接到搜索
vgs_model.php模型
public function pcList(){
$this->db->select('*');
$this->db->from('videogame');
$this->db->where('Format', 'PC');
$query = $this->db->get();
return $query->result();
}
的search.php控制器
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查看
<a href = <?php echo site_url('Hello/getPc'); ?>>View PC Games</a>
我已经收到以下错误
Message: Undefined property: Search::$Vgs_model
Filename: controllers/search.php
Line Number: 40
第40行是这样的 $data['results'] = $this->Vgs_model->pcList();
我在做什么错?任何帮助,将不胜感激。
感谢您阅读我的文章。
噢,我的上帝,是热闹!这样一个简单的错误。我喜欢用文本编辑器进行编程。非常感谢你查理。 – 2013-05-03 02:01:45
是的,我也使用文本编辑器进行编程,很高兴可以帮助:) – egig 2013-05-03 02:04:06
实际上,根据CI惯例,您的模型加载应该是'$ this-> load-> model('Vgs_model');'型号名称是大写。以上内容将保持大写,除非您在加载时指定第二个参数以不同地命名。请参阅http://ellislab.com/codeigniter/user-guide/general/models.html,但这只是坚持CI的方式,您应该使用这种方式,因为它可能会在后面的版本中产生意想不到的副作用。 – 2013-05-03 09:08:17