php – 路由[Controller @ method]未定义

前端之家收集整理的这篇文章主要介绍了php – 路由[Controller @ method]未定义前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图用一个对应的控制器方法创建一个表单,该方法向DB添加一个新的记录. 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] not defined.
(View: /var/www/virtual/hwoern/laravel/app/views/projects.blade.PHP)

使用列表方法在项目视图中显示现有项目工作正常.我忽略了什么?

您已收到未定义的Route [ProjectController @ createProject],因为您尚未创建任何用于ActionController @ createProject的后台路径.

您必须定义以下路线:

route.PHP

Route::post('new-project',array('uses' => 'ProjectController@createProject'));
原文链接:https://www.f2er.com/php/138209.html

猜你在找的PHP相关文章