Welcome Guest, Not a member yet? Register   Sign In
Problem with Tutorial, part II - "News section"...
#1

[eluser]Matteo[/eluser]
I am having trouble with the second tutorial here...

Code:
ellislab.com/forums/newtopic/51/

The first tutorial parsed fine for me, but this one is showing a blank page.

My model file ('news_model.php') has the following code...

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();
}

My view file ('views/news/index.php') looks like this...

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

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

&lt;?php endforeach ?&gt;

and the ('views/news/view.php') file looks like this...

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

For my controller file, I have the following...

Code:
&lt;?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');
}

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

I tried going through the tutorial 3 times, the last time simply cutting/pasting the code from the tutorial itself instead of typing it in (a better way to learn... Smile )

All I get is a blank page. No errors reporting, but no content either. (Yes, my database has 6 rows of data in it.)

Please help!
#2

[eluser]Unknown[/eluser]
I was getting the same blank page, I am new to using frameworks. I copied and pasted the code just to ensure that what was done was right.

However I found the solution http://www.phpfreaks.com/forums/index.ph...c=354265.0 where the code was clearly visable.
#3

[eluser]Unknown[/eluser]
I have tried all the suggestions in this and the suggested thread and still no success. I still get a blank page, and no error.

http://localhost/name/index.php/news is the url I'm using.

Anyone else have any other suggestions please?
#4

[eluser]morismc[/eluser]
I've also the same problem. After calling $this->load->model('news_model'); the page stays blank.




Theme © iAndrew 2016 - Forum software by © MyBB