2012-03-08 5 views
0

나는 튜토리얼을 수행 중이며 500 문제가 있습니다. 문제가 모델에 의한 것인지 아닌지는 잘 모르겠습니다. 내 모델 :500 내부 서버 오류 CodeIgniter

<?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; 
} 
} 

내 컨트롤러 :

<?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'); 

} 

} 

데이터베이스

$db['default']['database'] = 'testDIY'; 

과 내가 자동로드 파일에서 모델을 자동로드했습니다.

데이터베이스를 비우거나 임의의 이름을 입력하면 내부 서버 오류 500이 표시되지 않고 의미있는 오류 메시지가 표시됩니다. 지금 문제를 파악할 수 없습니까? 누구든지 도와 드릴 수 있습니까?

+0

의 그것은 일반적으로 서버 오류를 의미
를 사용하고 여기에 보인다. 어쩌면 그것은 나쁜 요청 일 것입니다. – gooddadmike

답변

1

문제는 $this->load->var($data);
대신
$this->load->vars($data);

+0

헤이, Shanyan, 고마워! 이제 작동합니다! – Mario

0

당신이 컨트롤러

public function index() 
{//homepage 

//Load the model 
$this->load->model('cat_model','',TRUE); 

    $data['title'] = "Welcome to TM testDIY"; 
    $data['navlist'] = $this->cat_model->getAllCategories(); 
    $this->load->var($data); 
    $this->load->view('template'); 

} 

당신은 또한보기

$ this->로드 ->보기 ('템플릿'에 $ 데이터를 보낼 필요가, $에서 모델을로드하지 않았다 데이터);

+0

질문을 신중하게 읽으면서 자신의 모델이 자동로드됨을 언급했습니다. –

+0

미안하다. –