CodeIgniter Forums

Full Version: Tutorial help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I'm just trying CI the first time. I'm following the tutorial from the manual here: https://www.codeigniter.com/user_guide/t...ction.html

I managed to get to the "Routing" section, but I'm getting an error when I try to access the URL: http://localhost:8080/codeigniter/index.php/news

The error is:
Quote:Fatal error: Cannot redeclare News::index() in F:\wamp64\www\codeigniter\application\controllers\News.php on line 32
A PHP Error was encountered
Severity: Compile Error
Message: Cannot redeclare News::index()
Filename: controllers/News.php
Line Number: 32

Here is the code from my News.php

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

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


Thanks
The error message says it all ... you have declared the index function twice: once below your constructor and again just before the end of the class. I think that the second version is meant to replace the first Undecided
Ahh, thanks Smile