PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] 500 Internal Server Error CodeIgniter

 March 14, 2022     codeigniter, model     No comments   

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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing