0

I'm new to this, and I was wondering why my controller appears twice on my URL. So I have a navbar, and when I click a menu, the URL looks like http://localhost/Home/index, but when I click another menu, the URL changes to http://localhost/Home/Home/stud_admit and shows the 404 - File Not Found, Controller method is not found: Home.

Routes.php

$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Home');
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(true);

$route['(:any)'] = "Home/$1";
$routes->get('/', 'Home::index');
$routes->get('/', 'Home::stud_admit');

Home.php - Controller

<?php
namespace App\Controllers;
use AppControllersBaseController;

class Home extends BaseController
{

  public function index() {
    $data = [];
    $data['title']   = 'SMS';
    $data['heading']    = 'Welcome to SMS';
    $data['main_content']   = 'home';   // page name
    echo view('innerpages/template', $data);
  }

    public function stud_admit()
    {
      $data = [];
      $data['title']        = 'SMS | ADMIT STUDENT';
      $data['heading']  = 'Welcome to SMS';
      $data['main_content'] = 'stud-admit'; // page name
      echo view('innerpages/template', $data);
    }
}
3
  • and its working fine ? Commented Mar 9, 2022 at 6:13
  • @AqibJaved nope. It shows the 404 - File Not Found Controller method is not found: Home Commented Mar 9, 2022 at 6:16
  • @cjwrk please show us your navbar/menu source code. Commented Mar 10, 2022 at 8:19

1 Answer 1

1

Because you have auto routing turned on, simply remove from your routes file:

$route['(:any)'] = "Home/$1"; $routes->get('/', 'Home::index'); $routes->get('/', 'Home::stud_admit');

You don't need them.

Sign up to request clarification or add additional context in comments.

2 Comments

The result is still the same even if I removed them.
I don't know what happened but it works now. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.