laravel Route.php 行中的 ReflectionException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35409418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:14:17  来源:igfitidea点击:

ReflectionException in Route.php line

phplaravel

提问by Sanjog Mittal

<?php 
class Myform  extends Controller
{
    public function index()
    {
        return view('form');
    }
}
?>

the code of routes

路线代码

Route::get('/myform', 'Myform@ndex');

and the error is

错误是

ReflectionException in Route.php line 264: Method App\Http\Controllers\Myform::ndex() does not exist

Route.php 第 264 行中的 ReflectionException:方法 App\Http\Controllers\Myform::ndex() 不存在

回答by dhruv jadia

change from

从改变

Route::get('/myform', 'Myform@ndex');

to

Route::get('/myform', 'Myform@index');

回答by Imtiaz Pabel

You did a typing mistake index instead of ndex

你打错了索引而不是索引

Route::get('/myform', 'Myform@index');

instead

反而

Route::get('/myform', 'Myform@ndex');

回答by Prashant Deshmukh.....

Remove /before myform, you don't need to put it.

去掉/before myform,就不用放了。

Declare the route as follows: Route::get('myform', 'Myform@index');

声明路由如下: Route::get('myform', 'Myform@index');

In your controller file add namespace App\Http\Controllers;at the top of your code.

在您的控制器文件中添加namespace App\Http\Controllers;代码的顶部。

<?php 
namespace App\Http\Controllers;
class Myform  extends Controller
{
    public function index()
    {
        return view('form');
    }
}
?>

Hope this will work.

希望这会奏效。