如何在laravel 5.0中将数据从视图发布到控制器?

时间:2015-10-12 06:04:27

标签: php laravel

我是laravel的新手,我试图将数据从视图传递到控制器,但却出现了一些错误。我搜索过但没有得到如何解决这个问题。请查看我的代码,并告诉我哪里错了?

demoview.blade.php代码

echo Form::open(array( 'method' => 'post','action' => 'DemoController@savess'));
echo Form::label('name', 'Name');
echo Form::text('name');
echo Form::label('email', 'E-Mail Address');
echo Form::text('email');
echo  Form::close();

DemoController.php代码

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

class DemoController extends Controller {

    /*
    |--------------------------------------------------------------------------
    | Welcome Controller
    |--------------------------------------------------------------------------
    |
    | This controller renders the "marketing page" for the application and
    | is configured to only allow guests. Like most of the other sample
    | controllers, you are free to modify or remove it as you desire.
    |
    */

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('guest');
    }

    /**
     * Show the application welcome screen to the user.
     *
     * @return Response
     */
    public function demofunction()
    {
        $users = \DB::table('user')->get();
        foreach ($users as $user)
        {
            echo  $user->name;
            echo  $user->email;
        }

        return view('demoview');
    }

    public function savess(){
    }
}

Routes.php代码

Route::get('demo', 'DemoController@demofunction');

错误:

ErrorException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined. (View: E:\xampp\htdocs\ayaz\resources\views\demoview.blade.php)




InvalidArgumentException in compiled.php line 8658:
Action App\Http\Controllers\DemoController@savess not defined.

1 个答案:

答案 0 :(得分:2)

将此行添加到routes.php

Route::post("savess", "DemoController@savess");