getting a "Uncaught TypeError: Argument 1 passed" in MVC starter framework
getting a "Uncaught TypeError: Argument 1 passed" in MVC starter framework
我是 MVC 的菜鸟,现在我是第一次创建 Auth
当我打开注册路线时:
致命错误:
Uncaught TypeError: Argument 1 passed to app\controllers\AuthController::register() must be an instance of app\controllers\Requset, instance of app\core\Request given in C:\controllers\AuthController.php:19
Stack trace: #0 [internal function]: app\controllers\AuthController->register(Object(app\core\Request)) #1 C:\MVC\core\Router.php(57)
: call_user_func(Array, Object(app\core\Request)) #2 C:\MVC\core\Application.php(30)
: app\core\Router->resolve() #3 C:\MVC\public\index.php(23)
: app\core\Application->run() #4 {main} thrown in C:\MVC\controllers\AuthController.php
on line 19
我的 AuthController class
namespace app\controllers;
use app\core\Controller;
use app\core\Application;
use app\core\Requset;
class AuthController extends Controller
{
public function login()
{
return $this->render('login');
}
public function register(Requset $request)
{
if($request->isPost()){
return 'Handle submitted data';
}
return $this->render('register');
}
}
如果有什么我搞砸了请告诉我把它包括在问题中
编辑
将 requset
编辑为 request
后:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function app\core\Controller::render(), 1 passed in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\controllers\AuthController.php on line 26 and exactly 2 expected in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Controller.php:14 Stack trace: #0 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\controllers\AuthController.php(26): app\core\Controller->render('register') #1 [internal function]: app\controllers\AuthController->register(Object(app\core\Request)) #2 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Router.php(57): call_user_func(Array, Object(app\core\Request)) #3 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Application.php(30): app\core\Router->resolve() #4 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\public\index.php(23): app\core\Application->run() #5 {main} thrown in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Controller.php on line 14
另一个编辑
渲染方法:
public function render($view, $params)
{
return Application::$app->router->renderView($view, $params);
}
在 return $this->render('register');
上有一个参数,该方法需要两个参数,视图的名称和 $params
,所以在寄存器中,我没有任何 $params
,所以这意味着$params
是可选的
为此,我将 $params
更改为 $params = []
所以如果我不写任何 $params
它将自动成为一个空数组
在代码中:
public function render($view, $params)
{
return Application::$app->router->renderView($view, $params);
}
到
public function render($view, $params = [])
{
return Application::$app->router->renderView($view, $params);
}
我是 MVC 的菜鸟,现在我是第一次创建 Auth
当我打开注册路线时:
致命错误:
Uncaught TypeError: Argument 1 passed to app\controllers\AuthController::register() must be an instance of app\controllers\Requset, instance of app\core\Request given in
C:\controllers\AuthController.php:19
Stack trace: #0 [internal function]: app\controllers\AuthController->register(Object(app\core\Request)) #1C:\MVC\core\Router.php(57)
: call_user_func(Array, Object(app\core\Request)) #2C:\MVC\core\Application.php(30)
: app\core\Router->resolve() #3C:\MVC\public\index.php(23)
: app\core\Application->run() #4 {main} thrown inC:\MVC\controllers\AuthController.php
on line 19
我的 AuthController class
namespace app\controllers;
use app\core\Controller;
use app\core\Application;
use app\core\Requset;
class AuthController extends Controller
{
public function login()
{
return $this->render('login');
}
public function register(Requset $request)
{
if($request->isPost()){
return 'Handle submitted data';
}
return $this->render('register');
}
}
如果有什么我搞砸了请告诉我把它包括在问题中
编辑
将 requset
编辑为 request
后:
Fatal error: Uncaught ArgumentCountError: Too few arguments to function app\core\Controller::render(), 1 passed in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\controllers\AuthController.php on line 26 and exactly 2 expected in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Controller.php:14 Stack trace: #0 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\controllers\AuthController.php(26): app\core\Controller->render('register') #1 [internal function]: app\controllers\AuthController->register(Object(app\core\Request)) #2 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Router.php(57): call_user_func(Array, Object(app\core\Request)) #3 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Application.php(30): app\core\Router->resolve() #4 C:\Users\xxgam\OneDrive\Desktop\projects\MVC\public\index.php(23): app\core\Application->run() #5 {main} thrown in C:\Users\xxgam\OneDrive\Desktop\projects\MVC\core\Controller.php on line 14
另一个编辑
渲染方法:
public function render($view, $params)
{
return Application::$app->router->renderView($view, $params);
}
在 return $this->render('register');
上有一个参数,该方法需要两个参数,视图的名称和 $params
,所以在寄存器中,我没有任何 $params
,所以这意味着$params
是可选的
为此,我将 $params
更改为 $params = []
所以如果我不写任何 $params
它将自动成为一个空数组
在代码中:
public function render($view, $params)
{
return Application::$app->router->renderView($view, $params);
}
到
public function render($view, $params = [])
{
return Application::$app->router->renderView($view, $params);
}