duankuang7928
2017-11-30 15:10
浏览 25
已采纳

动作未定义laravel / php控制器

I am having a problem with a controller action in a laravel project and I have no idea why, since everything seems fine.

Heres my route concerning the error part:

Route::get('/reminds','RemindController@index');
Route::get('/reminds','RemindController@create');

Heres the create and index method that are defined in the RemindController.php file:

    public function index()
{
    $reminds  = Remind::all();
    return View::make('remind.index', compact('reminds'));
}



public function create()
{
    try {


        $listyears = RemindController::generate_list(date('Y')-100, 101);
        $listmonths = RemindController::generate_list(1, 12);
        $listdays = RemindController::generate_list(1, 31);

        return View::make('remind.create', compact('listyears', 'listmonths', 'listdays'));
    } catch (Exception $e){
        App:abort(404);
    }
}

In create.blade.php(of remind view) I have this that calls the problematic index:

    <div class="panel-heading">
    <h2>create reminder</h2>
</div>
<div class="panel-body">
    {!! Form::open(['action'=> 'RemindController@index', 'class' => 'form']) !!}

The problem is that each time I try to access the page that calls the reminder creation form I get error:

ErrorException (E_ERROR)
Action App\Http\Controllers\RemindController@index not defined. (View: C:\Users\myusername\Desktop\project\prototypeesources\viewsemind\create.blade.php)

However I clearly defined it. I dont understand. Thank you

图片转代码服务由CSDN问答提供 功能建议

我在laravel项目中遇到控制器动作的问题,我不明白为什么,因为一切似乎都很好 。

下面是关于错误部分的路线:

  Route :: get('/ reminds','RemindController @ index')  ; 
Route :: get('/ reminds','RemindController @ create'); 
   
 
 

继承人RemindController.php中定义的create和index方法 file:

  public function index()
 {
 $ reminds = Remind :: all(); 
返回View :: make('remind.index',  compact('reminds')); 
} 
 
 
 
公共函数create()
 {
 try {
 
 
 $ listyears = RemindController :: generate_list(date('Y'))  -100,101); 
 $ listmonths = RemindController :: generate_list(1,12); 
 $ listdays = RemindController :: generate_list(1,31); 
 
返回View :: make('remind.create  ',compact('listyears','listmonths','listdays')); 
} catch(Exception $ e){
 App:abort(404); 
} 
} 
    
 
 

在create.blade.php(提醒视图)中我有这个调用有问题的索引:

 &lt  ; div class =“panel-heading”&gt; 
&lt; h2&gt;创建提醒&lt; / h2&gt; 
&lt; / div&gt; 
&lt; div class =“panel-body”&gt; 
 {!!  Form :: open(['action'=&gt;'RemindController @ index','class'=&gt;'form'])!!} 
   
 
 

问题是每次我尝试访问调用提醒创建表单的页面时都会收到错误:

  ErrorException(E_ERROR)
Action App \ Http \ Controllers \ RemindController @ index 没有定义的。  (查看:C:\ Users \ myusername \ Desktop \ project \ prototype 
esources \ views 
emind \ create.blade.php)
   
 
 

但是我明确定义了它 。 我不明白 谢谢

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dsiimyoc804955 2017-11-30 15:13
    已采纳

    Route::get('/reminds','RemindController@index'); Route::get('/reminds','RemindController@create');

    this is the same route, so technically on this part you have an issue already. try to change the HTTP protocol or rename your route instead.

    Route::get('reminds','RemindController@index');
    Route::post('reminds','RemindController@create');
    

    or

    Route::get('reminds','RemindController@index');
    Route::get('reminds/create','RemindController@create');
    

    also omit the first slash on your route already, there's no use of doing that.

    --- update*

    instead of using the static call Route

    you may use something like this

    $router->group(function(){
       $this->get('/',['as' => "homepage" , 'use' => "MainController@homepage"] );
    
       $this->group(['prefix' => "dashboard",'as' => "dashboard"],function(){
          $this->get('/',['as' => "index",'use' => "DashboardController@index"]);
    });
    });
    
    打赏 评论
  • douruobokui58233 2017-11-30 15:12

    You defined two routes with same url and same method

    Route::get('/reminds','RemindController@index');
    Route::get('/reminds','RemindController@create');
    

    Rename one of them

    Route::get('/reminds','RemindController@index');
    Route::get('/reminds/create','RemindController@create');
    
    打赏 评论
  • doulierong0334 2017-11-30 15:38

    You have written same route url for same http verb.

    Just rename them as your requirement. A suggestion to add name() for route for simplicity.

    打赏 评论

相关推荐 更多相似问题