0

I'm following the Codeigniter tutorial: http://localhost:8080/myproject/user_guide/tutorial/news_section.html

When i point my browser to http://localhost:8080/myproject/news as the tutorial indicates at the final of the section, "Point your browser to your document root, followed by index.php/news and watch your news page." appears a blank page.

I tried to point to localhost:8080/index.php/news or /myproject/news but occurs the same problem.

Also i tried to set in autoload.php the next: $autoload['libraries'] = array('database'); as is indicated in codeigniter news section tutorial not working but not solve, so i leave it like this: $autoload['libraries'] = array('');

This is the routes:

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

The News.php:

   <?php
   class News extends CI_Controller {

    public function __construct()
    {
            parent::__construct();
            $this->load->model('news_model');
            $this->load->helper('url_helper');
    }

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

    public function view($slug = NULL)
   {
    $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');
   }
   }

the view.php:

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

and the News_model.php:

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

I expect to watch the news page

  • 1
    Possible duplicate of https://stackoverflow.com/questions/1475297/phps-white-screen-of-death – 04FS Jun 05 '19 at 06:47
  • i checked Errors in /logs/php_error.log or ..../logs/apache_error.log as the link indicates, but nothing appears. I'm a beginner and probably there is a mistake that will be very simple, but for me is taking a lot of time to find the problem. – Andrés Mangas Jiménez Jun 05 '19 at 17:33
  • 1
    First question. Did you go through the whole tutorial? I see you have not provided the code where you create the news item. Second Question, did you create your templates/header.php and templates/footer.php views with something in those to display? In your News.php controllers constructor you can do a simple echo "Hi I got here"; to see if that shows anything and work from there. – TimBrownlaw Jun 06 '19 at 09:58
  • Finally i solved the problem but i don't know exactly where was the problem located, simply i deleted the templates and other files, and make the tutorial again and worked fine! So probably i wrote wrong the code of a php file. Thanks for the help. – Andrés Mangas Jiménez Jun 07 '19 at 10:04

0 Answers0