CodeIgniter Forums
Controller or its method is not found - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Controller or its method is not found (/showthread.php?tid=90462)



Controller or its method is not found - mylastof - 03-21-2024

I’ve recently upgraded CodeIgniter from v4.3.8 to v4.4.0 and encountered an issue with routing.
My controller is located at app/Controllers/Member/Dashboard.php and is set up for auto-routing.

However, when I attempt to access the URL http://localhost:8080/member/dashboard, I receive the following error:

Code:
Controller or its method is not found: \App\ControllersMember\Dashboard::index

I’ve verified with
Code:
php spark routes
that the URL route is indeed defined.

Could someone guide me on how to resolve this?


RE: Controller or its method is not found - mylastof - 03-21-2024

why
PHP Code:
\App\ControllersMember\Dashboard::index 
not
PHP Code:
\App\Controllers\Member\Dashboard::index 



RE: Controller or its method is not found - mylastof - 03-23-2024

bring up my post


RE: Controller or its method is not found - kenjis - 03-23-2024

Show the output of `php spark routes`, and the routing settings.


RE: Controller or its method is not found - mylastof - 03-23-2024

(03-23-2024, 07:21 PM)kenjis Wrote: Show the output of `php spark routes`, and the routing settings.

here the result `php spark routes`
[Image: routes.png]

`app/Config/Routing.php`
[Image: routing.png]

and the result in browser
[Image: 404.png]


RE: Controller or its method is not found - kenjis - 03-24-2024

Cannot reproduce.


PHP Code:
<?php

namespace App\Controllers\Member;

use 
App\Controllers\BaseController;
use 
CodeIgniter\HTTP\ResponseInterface;

class 
Dashboard extends BaseController
{
    public function index()
    {
        return __METHOD__;
    }


Code:
diff --git a/app/Config/Routes.php b/app/Config/Routes.php
index fc4914a692..80226ae341 100644
--- a/app/Config/Routes.php
+++ b/app/Config/Routes.php
@@ -5,4 +5,4 @@ use CodeIgniter\Router\RouteCollection;
/**
  * @var RouteCollection $routes
  */
-$routes->get('/', 'Home::index');
+//$routes->get('/', 'Home::index');
diff --git a/app/Config/Routing.php b/app/Config/Routing.php
index 47bf5ff8e5..e1941480f9 100644
--- a/app/Config/Routing.php
+++ b/app/Config/Routing.php
@@ -61,7 +61,7 @@ class Routing extends BaseRouting
      *
      * Default: false
      */
-    public bool $translateURIDashes = false;
+    public bool $translateURIDashes = true;

    /**
      * Sets the class/method that should be called if routing doesn't
@@ -89,7 +89,7 @@ class Routing extends BaseRouting
      *
      * If FALSE, will stop searching and do NO automatic routing.
      */
-    public bool $autoRoute = false;
+    public bool $autoRoute = true;

    /**
      * If TRUE, will enable the use of the 'prioritize' option

Code:
$ php spark routes

CodeIgniter v4.4.6 Command Line Tool - Server Time: 2024-03-25 01:28:52 UTC+00:00

+--------+------------------------------+------+------------------------------------------+----------------+---------------+
| Method | Route                        | Name | Handler                                  | Before Filters | After Filters |
+--------+------------------------------+------+------------------------------------------+----------------+---------------+
| auto  | /                            |      | \App\Controllers\Home::index            |                | toolbar      |
| auto  | home                        |      | \App\Controllers\Home::index            |                | toolbar      |
| auto  | home/index[/...]            |      | \App\Controllers\Home::index            |                | toolbar      |
| auto  | member/dashboard            |      | \App\Controllers\Member\Dashboard::index |                | toolbar      |
| auto  | member/dashboard/index[/...] |      | \App\Controllers\Member\Dashboard::index |                | toolbar      |
+--------+------------------------------+------+------------------------------------------+----------------+---------------+

Navigate to http://localhost:8080/member/dashboard,
I see
Code:
App\Controllers\Member\Dashboard::index



RE: Controller or its method is not found - kenjis - 03-24-2024

Upgrade to v4.4.6.

Auto Routing Legacy does not work in v4.4.0.
See https://codeigniter4.github.io/CodeIgniter4/changelogs/v4.4.1.html#bugs-fixed