Issue
I'm following a tutorial and got the 500 problem. I'm not sure the problem is caused by model or not. My model:
<?php
class Cat_model extends CI_Model{
public function __construct()
{
$this->load->database();
}
function getCategory($id){
$data = array();
//select one row matching that ID from the categories table
$options = array('id'=>$id);
$q = $this->db->get_where('categories',$options,1);
if($q->num_rows()>0){
$data = $q->row_array();
}
$q->free_result();
return $data;
}
function getAllCategories(){
$data = array();
$q = $this->db->get('categories');
if($q->num_rows()>0){
foreach ($q->result_array() as $row){
$data[] = $row;
}
}
$q->free_result();
return $data;
}
}
my controller:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{//homepage
$data['title'] = "Welcome to TM testDIY";
$data['navlist'] = $this->cat_model->getAllCategories();
$this->load->var($data);
$this->load->view('template');
}
}
Database
$db['default']['database'] = 'testDIY';
and i've autoload the model in autoload file.
If i empty the database or put some random name there, it won't show 500 internal server error, instead, it shows some meaningful error msg. I can't figure out the problem now, anyone could help?
Solution
Problem seems to be here you have used
$this->load->var($data);
instead of
$this->load->vars($data);
Answered By - Code Prank
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.