Welcome Guest, Not a member yet? Register   Sign In
unexpected 'public' (T_PUBLIC)
#1

Hello,

controllers/Pages.php


PHP Code:
<?php


class Pages extends CI_Controller {

 
     

    
public function view($page 'home')
    {
 
       if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))
            {
 
               // Whoops, we don't have a page for that!
 
               show_404();
            }

            
$data['title'] = ucfirst($page); // Capitalize the first letter

            
$this->load->view('templates/header'$data);
            
$this->load->view('pages/'.$page$data);
            
$this->load->view('templates/footer'$data);
    }

}

?>



How to fix this error line # 13?

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


Line 12 - 13:   if ( ! file_exists(APPPATH.'views/pages/'.$page.'.php'))

            {  


I do not know how to fix the error.  Can anyone help?
" If I looks more intelligence please increase my reputation."
Reply
#2

Might sound daft, by try removing the closing php tag.

(Might not help too - but I never include them.)
Reply
#3

Remove the "public" keyword before the controller function. Surely that's what it means when it says: "unexpected 'public'".
Reply
#4

Using public or private is a good idea though, and should not in itself cause an issue. Usually this happens when I forget the curly brace but he has it.

He also has removed the basepath check, which was probably him trying to fix another problem, I suspect he has got the whole file structure and CI implementation wrong in the first place.

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

Paul.
Reply
#5

I think he needs to learn PHP before trying to learn CodeIgniter.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

try removing that closing: ?>

its probably the problem. if its not, then post again and someone will try to help.
what is not a problem - is you learning how to code. i salute you doing the right thing and working through the tutorial. i encourage your efforts. it is difficult and confusing at first, but it does get easier. and you will find that sometimes the issues that take the longest to solve - are just a few characters in length.
Reply
#7

The provided code probably has not been pasted exactly. I think there is something between the class declaration and the first method that we can not see.
Reply
#8

That would make sense, then an un-closed if statement, say, would cause the unexpected public declaration.
Reply
#9

Perhaps the missing constructor?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB