Welcome Guest, Not a member yet? Register   Sign In
Parse error: syntax error, unexpected 'function_construct' (T_STRING), expecting variable (T_VARIABLE) in C:wampwwwframe
#1

[eluser]Dario[/eluser]
Hi!

I just started using CodeIgniter and to get to know with the system i started writing the tutorial that comes with it. Was very entusiastic until i tried to view my news page Smile. the error i get is Parse error: syntax error, unexpected 'function_construct' (T_STRING), expecting variable (T_VARIABLE) in C:\wamp\www\framework\application\controllers\news.php on line 5.

This is the code
Code:
<?php

class News extends CI_Controller {

public function_construct()
{
  parent::_construct();
  $this->load->model('news_model');
}

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

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

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

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

Thank you!!
#2

[eluser]Aken[/eluser]
It tells you exactly what the error is, and what line it's on. Look at that line and figure it out.
#3

[eluser]Dario[/eluser]
Thank you for your reply!

The thing is that i just started to use the framework and i started by writing it from the tutorial that came with CodeIgniter and this is the code:

Code:
<?php

class News extends CI_Controller {

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

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

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

from file:///C:/wamp/www/framework/user_guide/tutorial/news_section.html ... I really just started learning Smile
#4

[eluser]rochellecanale[/eluser]
Just need a little spacing here:

Code:
public function_construct() //seperate function and __construct() it should be public function __construct()
{
  parent::_construct();
  $this->load->model('news_model');
}
#5

[eluser]Dario[/eluser]
Thank you! Smile




Theme © iAndrew 2016 - Forum software by © MyBB