Search code examples
phpcodeigniterroutescontroller

Routes and Controller problem on Codeigniter 4, can't access


Routes and Controller problem on Codeigniter 4, can't access

I created Controller and Routes, and I created a Navbar.php file in Controller with methods and GET in Routes, then can not be accessed with localhost CI. I need a solution because I'm just learning CI4, thank you.

This is the code.

Routes setting

// We get a performance increase by specifying the default
// route since we don't have to scan directories.
$routes->get('/', 'Home::index');
$routes->get('/about', 'Navbar::about');
$routes->get('/contact', 'Navbar::contact');
$routes->get('/faqs', 'Navbar::faqs');

Navbar.php

<?php namespace App\Controllers;

class Page extends BaseController
{
    public function about()
    {
        echo "about page";
    }
    
    public function contact()
    {
        echo "contact page";
    }
    
    public function faqs()
    {
        echo "faqs page";
    }

}

I want to know where's error, need to problem solving with help.


Solution

  • You should be change your class name in Navbar.php file where your controller name is Navbar.php but your class name is Page.

    thanks