• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
News section

#1
ParseError

syntax error, unexpected 'public' (T_PUBLIC), expecting end of file


APPPATH\Controllers\News.php at line 23
Code:
16     {
17         $model = new NewsModel();
18
19         $data['news'] = $model->getNews($slug);
20     }
21 }
22
23 public function index()
24 {
25     $model = new NewsModel();
26
27     $data = [
28         'news'  => $model->getNews(),
29         'title' => 'News archive',
30     ];
Reply

#2
i can only see what you have posted but index method is missing a curly brace, above that it looks un complete could be:


Code:
public function index()
{
        

     $model = new NewsModel();  
     $data['news'] = $model->getNews($slug);
     $data = [
         'news'  => $model->getNews(),
         'title' => 'News archive', // there is no other item so "," not needed


     ];


} //end of method
Reply

#3
(01-14-2021, 10:22 AM)captain-sensible Wrote: i can only see what you have posted but index method is missing a curly brace, above that it looks un complete could  be:


Code:
public function index()
{
       

     $model = new NewsModel(); 
     $data['news'] = $model->getNews($slug);
     $data = [
         'news'  => $model->getNews(),
         'title' => 'News archive', // there is no other item so "," not needed


     ];


} //end of method

my code, this code from CodeIgniter4 User Guide

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\NewsModel;
use 
CodeIgniter\Controller;

class 
News extends Controller
{
    public function index()
    {
        $model = new NewsModel();

        $data['news'] = $model->getNews();
    }

    public function view($slug null)
    {
        $model = new NewsModel();

        $data['news'] = $model->getNews($slug);
    }
}

public function 
index()
{
    $model = new NewsModel();

    $data = [
        'news'  => $model->getNews(),
        'title' => 'News archive',
    ];

    echo view('templates/header'$data);
    echo view('news/overview'$data);
    echo view('templates/footer'$data);

Reply

#4
(01-14-2021, 10:50 AM)vojkoz Wrote:
(01-14-2021, 10:22 AM)captain-sensible Wrote: i can only see what you have posted but index method is missing a curly brace, above that it looks un complete could  be:


Code:
public function index()
{
       

     $model = new NewsModel(); 
     $data['news'] = $model->getNews($slug);
     $data = [
         'news'  => $model->getNews(),
         'title' => 'News archive', // there is no other item so "," not needed


     ];


} //end of method

my code, this code from CodeIgniter4 User Guide

PHP Code:
<?php namespace App\Controllers;

use 
App\Models\NewsModel;
use 
CodeIgniter\Controller;

class 
News extends Controller
{
    public function index()
    {
        $model = new NewsModel();

        $data['news'] = $model->getNews();
    }

    public function view($slug null)
    {
        $model = new NewsModel();

        $data['news'] = $model->getNews($slug);
    }
}

public function 
index()
{
    $model = new NewsModel();

    $data = [
        'news'  => $model->getNews(),
        'title' => 'News archive',
    ];

    echo view('templates/header'$data);
    echo view('news/overview'$data);
    echo view('templates/footer'$data);

now you are confusing me ; two methods both called Index ? you can't have that
Reply

#5
When your reading the tutorial you should update the index or other methods not add them in again.

In other words you should replace the code or add the code to the method mentioned.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#6
You are declaring a method outside the class
Reply

#7
You must replace the second index function with oldone, here an image explication:

   
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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