CodeIgniter Forums
News section - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Addins (https://forum.codeigniter.com/forumdisplay.php?fid=34)
+--- Thread: News section (/showthread.php?tid=78401)



News section - vojkoz - 01-14-2021

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     ];



RE: News section - captain-sensible - 01-14-2021

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



RE: News section - vojkoz - 01-14-2021

(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);




RE: News section - captain-sensible - 01-14-2021

(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


RE: News section - InsiteFX - 01-14-2021

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.


RE: News section - iRedds - 01-15-2021

You are declaring a method outside the class


RE: News section - nicojmb - 01-15-2021

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