CodeIgniter Forums
Updated News Tutorial - Printable Version

+- CodeIgniter Forums (
+-- Forum: Using CodeIgniter (
+--- Forum: General Help (
+--- Thread: Updated News Tutorial (/showthread.php?tid=64259)

Updated News Tutorial - cisite - 01-31-2016

Hi everyone,

I have been struggling with the news tutorial.
has anyone been able to make it work, from beginning to the end?

I have followed it to the letter (copy/paste everything) but the links to the individual news do not work.
I continued to the end and the success page does not display (after an entry, the form clears and reloads)

I am sure that smart folks here have identified the error in the code, as presented in the tutorial, and made the whole thing work.

If it is possible .... if you made the code correction/s and it everything now works for you, would you mind posting the codes here?

I noticed elsewhere in the forum many people having problem with it -- wonder if those in admin tried the code themselves --as is presented -- and see where improvement/s in the coding could be updated.

CI is a very nice framework, and it's a shame that newbies move on because they could not get a very basic tutorial to work -- not due to lack of understanding of it, but because the code as is presented does not work.

Personally, I will not give up -- I know there are many kind and helpful folks on this forum and somehow I will get the assistance to make the tutorial work. When that time comes I will then post the corrected posts for others to benefit from.

Thank you all.

RE: Updated News Tutorial - cisite - 02-02-2016


Someone most likely made the news tutorial work .... somehow.

To those who did, anyone willing to share the code used?

RE: Updated News Tutorial - Paradinight - 02-07-2016

The tutorial is not wrong. I have made a testsite. No errors and no warnings Huh

What is the problem? Make a screen or show me the error message.

Quote:After this, a view is loaded to display a success message. Create a view at application/views/news/success.php and write a success message.

RE: Updated News Tutorial - RobertSF - 02-07-2016

Hey, I'm glad you're not going to give up! I too remember having problems with the tutorial, and I remember thinking exactly what you're thinking -- how are they going to attract new users if the darn tutorial doesn't even work? I remember moving on from the tutorial, leaving it unfinished, and just starting to work on a real project.

After reading your post, I did a clean CI install and cut-and-pasted my way through the tutorial. I missed the part about creating a success page, so I got an error, but after creating the success page, everything worked. The links to the news items are correct in my case. I called the item I entered first-news, and the link to it is http://localhost/citutorial/news/first-news, so it works.

I don't know what the problem might be in your case, but as tedious as it may sound, go over it again, and make sure every step got done. The wrong capitalization of file names can cause problems, so double-check that. Also, if you get the wrong links to your news items, what are those wrong links? How are they wrong?

What is your level of PHP knowledge and programming in general? Are you starting all three at once (programming, PHP, and CI)?

Well, all I can recommend is patience. Programming is like watchmaking, very detail oriented, and small things keep the whole thing from working. If you have general programming, PHP, or MySQL questions, a great forum is It gets a lot of traffic, and most of the people there are pretty friendly. I can also suggest, but on a read-only basis. The people there tend to bite newbies asking "dumb" questions, but the answers they do give are really good!

RE: Updated News Tutorial - InsiteFX - 02-08-2016

Most of the problems are because they do not add the routes to the tutorial.

RE: Updated News Tutorial - josemg - 09-17-2016

(02-08-2016, 05:00 AM)InsiteFX Wrote: Most of the problems are because they do not add the routes to the tutorial.

       (i am not english native sorry for my english)

I have this error

Parse error: syntax error, unexpected 'public' (T_PUBLIC) in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models\News_model.php on line 10
A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected 'public' (T_PUBLIC)
Filename: models/News_model.php
Line Number: 10

Is my route bad  ??

This is my News_model.php

class News_model extends CI_Model {

        public function __construct()

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 News.php


class News extends CI_Controller {

        public function __construct()

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

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

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

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

                      My view.php

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

                     My index.php

<h2><?php echo $title; ?></h2>

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

        <h3><?php echo $news_item['title']; ?></h3>
        <div class="main">
                <?php echo $news_item['text']; ?>
        <p><a href="<?php echo site_url('news/'.$news_item['slug']); ?>">View article</a></p>

<?php endforeach; ?>

                     My routes.php

defined('BASEPATH') OR exit('No direct script access allowed');

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

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

$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;


The pages example run ok, aftaer that I set the rules for news before pages, but news do no run give me that parse error.

In database.php,   I add a final line becasue my Mysql has a 3308 port

$db['default']['port'] = 3308;

Windows 7 with EASYPHP DEVSERVER   version : 16.1.1
 PHP 5.6.19 x86  Mysql 5.7

My paths
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\controllers
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\models
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views\news
C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\application\views\templates

If someone see something wrong please tell me


RE: Updated News Tutorial - InsiteFX - 09-18-2016

This is wrong in the News Tutorial:

PHP Code:
// Tutorial is wrong here!


// should be


// you have an error here

class News_model extends CI_Model {

   public function __construct()
// <-- remove this its an extra one...

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

Most people do not catch it because they autoload the url helper in ,/application/autoload.php

Also in your routes you need to move all routes with a /(:any) in them to the bottom,
the any is a catch all route and no routes after it will run.

This error is usually syntax error: Missing bracket, too many closing brackets, etc;
Message: syntax error, unexpected 'public' (T_PUBLIC)