路径[Controller @ method]未定义

时间:2014-01-04 10:20:21

标签: php laravel-4

我正在尝试使用相应的控制器方法创建一个表单,该方法将新记录添加到数据库中。 Laravel版本是4.1

应用/视图/ projects.blade.php

<tr>
   {{Form::open(array('action' => 'ProjectController@createProject', 'method' => 'post'))}}
        <td>{{Form::text('project_number')}}</td>
        <td>{{Form::text('title')}}</td>
        <td>{{Form::text('client')}}</td>
        <td>{{Form::text('comment')}}</td>
        <td>
            {{Form::file('xmlfile')}}<br />
            {{Form::submit('Hinzufügen',array('class' => 'blue'))}}
        </td>
   {{ Form::close() }}
</tr>

应用/控制器/ ProjectController

<?php

class ProjectController extends BaseController {

    public function listProjects(){
        $projects = Project::all();
        return View::make('projects',array('projects' => $projects));
    }

    public function createProject(){
        /* handling the form data later
            .
            .
            .
            */
        return "Hello"; 
    }   
}
?>

routes.php文件

// Project Routes
Route::get('/projects', array('as' => 'listProjects', 'uses' => 'ProjectController@listProjects'));
Route::get('/projects/{id}', array('as' => 'actionProject', 'uses' => 'ProjectController@actionProject'));

// Canal Routes
Route::get('/canals', array('as' => 'listCanals', 'uses' => 'CanalController@listCanals'));

错误消息

  

ErrorException Route [ProjectController @ createProject]未定义。   (查看:/var/www/virtual/hwoern/laravel/app/views/projects.blade.php)

在项目视图中使用list方法显示现有项目可以正常工作。我忽略了什么?

1 个答案:

答案 0 :(得分:27)

您已收到Route [ProjectController@createProject] not defined,因为您尚未为行动ProjectController@createProject创建任何邮寄路线。

您必须定义以下路线:

<强> route.php

Route::post('new-project', array('uses' => 'ProjectController@createProject'));