• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Syntax error, unexpected 'public' (T_PUBLIC)

#1
Hy

I hope that I'm opening this topic in the correct section.

I started to study CI_tutorial and now i stopped from many hours by a problem about a news_model. 
When run the tutorial's example get the error: 


A PHP Error was encountered
Severity: Warning
Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\httpg\application\models\news_model.php:10)
Filename: core/Common.php
Line Number: 570
Backtrace:


A PHP Error was encountered
Severity: Parsing Error
Message: syntax error, unexpected 'public' (T_PUBLIC)
Filename: models/news_model.php
Line Number: 10
Backtrace:


This is the code of news_model.php
Tahnk you for help!
Luigi Confused


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

#2
The error is exactly what it says, unexpected 'public' on line 10. Check out line 10. Check out your class and how it only contains a __construct() function.

PHP does a decent job most of the time telling you where an error is. Always check the simple things and don't be so quick to give up.
Reply

#3
The issue is with the get_news function, which is not in a class.
As it is not in a class, you can't declare it as public.
Either remove public, or put the function in the class, and you'll be fine.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2017 MyBB Group.