Welcome Guest, Not a member yet? Register   Sign In
News Section Tutorial - 500 Internal Server Error
#1

[eluser]imwithsam[/eluser]
I'm brand new to CodeIgniter and am trying to work my way through the tutorials on my localhost. I made it through the Static Pages tutorial just fine, but am stuck on the News Section tutorial. I keep receiving a 500 Internal Server error. I've looked over my code multiple times, and am missing what I'm doing wrong. Does anyone have any suggestions? FYI, I'm running my application and system directories outside my root. Thanks in advance!

routes.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$route['news/(:any)'] = "news/view/$1";
$route['news'] = "news";
$route['default_controller'] = "pages/view";
$route['(:any)'] = "pages/view/$1";
$route['404_override'] = '';

database.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'mcn';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

news_model.php model
Code:
<?php
class News_model extends CI_Model {
  public function __construct()
  {
    $this->load->database();
  }

  public function get_news($slug = FALSE)
  {
    if ($slug === FALSE)
    {
      $query = $this->db->get('news');
      return $query->result_array();
    }

    $query = $this->db->get_where('news', array('slug' => $slug));
    return $query->row_array();
  }
}

news.php controller
Code:
<?php
class News extends CI_Controller {
  public function __construct()
  {
    parent::__construct();
    $this->load->model('news_model');
  }

  public function index()
  {
    $data['news'] = $this->news_model->get_news();
    $data['title'] = 'News archive';

    $this->load->view('templates/header', $data);
    $this->load->view('news/index', $data);
    $this->load->view('templates/footer', $data);
  }

  public function view($slug)
  {
    $data['news_item'] = $this->news_model->get_news($slug);

    if (empty($data['news_item']))
    {
      show_404();
    }

    $data['title'] = $data['news_item']['title'];

    $this->load->view('templates/header'), $data);
    $this->load->view('news/view', $data);
    $this->load->view('templates/footer', $data);
  }
}

index.php view
Code:
<?php foreach ($news as $news_item): ?>

  <h2>&lt;?php echo $news_item['title'] ?&gt;</h2>
  <div class="main">
    &lt;?php echo $news_item['text'] ?&gt;
  </div>
  <p><a href="news/&lt;?php echo $news_item['slug'] ?&gt;">View article</a></p>

</?php endforeach ?&gt;

view.php view
Code:
&lt;?php
echo '<h2>'.$news_item['title'].'</h2>';
echo $news_item['text'];


Messages In This Thread
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 06:59 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 07:07 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 07:15 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 08:06 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 08:47 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-05-2014, 09:54 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-06-2014, 06:02 AM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-06-2014, 03:25 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-06-2014, 03:55 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-06-2014, 06:20 PM
News Section Tutorial - 500 Internal Server Error - by El Forum - 08-06-2014, 07:06 PM



Theme © iAndrew 2016 - Forum software by © MyBB