bramus / router

A lightweight and simple object oriented PHP Router
MIT License
1.09k stars 247 forks source link

Unable to Call to Controller Method with Uncaught TypeError: stripos() #222

Open CasperHK opened 2 weeks ago

CasperHK commented 2 weeks ago

I would like to call to the loadDashboard() method in \App\Http\Controllers\DashboardController class but failed. The program are somethings like:

use Common\DatabaseConnection;
use Bramus\Router\Router;
use Opis\Database\Database;
use App\Http\Controllers\DashboardController;

$router = new Router();
$router->get('/', [DashboardController::class, 'loadDashboard']);
$router->run();

Error Message

Fatal error: Uncaught TypeError: stripos(): Argument #1 ($haystack) must be of type string, array given in 
C:\xampp\htdocs\EVS\vendor\bramus\router\src\Bramus\Router\Router.php:462 Stack trace: #0 
C:\xampp\htdocs\EVS\vendor\bramus\router\src\Bramus\Router\Router.php(462): stripos(Array, '@') #1 
C:\xampp\htdocs\EVS\vendor\bramus\router\src\Bramus\Router\Router.php(440): Bramus\Router\Router->invoke(Array, Array) #2 
C:\xampp\htdocs\EVS\vendor\bramus\router\src\Bramus\Router\Router.php(287): Bramus\Router\Router->handle(Array, true) #3 
C:\xampp\htdocs\EVS\router.php(251): Bramus\Router\Router->run() #4 
{main} thrown in C:\xampp\htdocs\EVS\vendor\bramus\router\src\Bramus\Router\Router.php on line 462

Please help to resolve the issue.

CasperHK commented 2 weeks ago

I have already tested to return a string in the loadDashboard method but the problem stil exist. And, I have also tried the Class@Method calls but it also does not work.

$router->get('/', "\App\Http\Controllers\DashboardController@loadDashboard");
CasperHK commented 2 weeks ago

Check the loadDashboard method: Make sure the loadDashboard method in DashboardController returns a string. For example:

public function loadDashboard() { return 'Welcome to the Dashboard!'; }

Also, you can use Servbay instead of Xampp to deploy. Servbay can install the packages you need and eliminate environment bugs

It appears that Servbay is only supported in a Mac environment, but I am using Windows for the development.