将变量从一个视图传递到另一个视图-Laravel 5.1 [英] Passing Variable From One View to Another View - Laravel 5.1
问题描述
在回答完我上一个问题之后,我复制了最上面的回答说的所有内容,这对他来说非常有效,而对我却不行.
After an answer to my previous question, I replicated everything the top answer said and it works perfectly for him while it doesn't for me.
我想在我的主页上(作家和读者)上放置两个按钮,这两个按钮会将它们定向到注册页面,并将该职业作为隐藏字段显示在表单中.
I want to put two buttons on my home page (Writer & Reader) which will direct them to registration page and put the profession as a hidden field in the form.
我的主页:
{!! Form::open(['route' => ['writer_path']]) !!}
{!! Form::hidden('profession', 'writer') !!}
{!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}
我的routes.php
My routes.php
Route::post('auth/register', [
'as' => 'writer_path',
'uses' => 'ProfessionController@displayForm'
]);
ProfessionController.php
ProfessionController.php
class ProfessionController extends Controller
{
//
public function displayForm()
{
$input = Input::get();
$profession = $input['profession'];
return view('auth/register', ['profession' => $profession]);
}
}
当我单击按钮时,什么也没有发生.当我检查开发人员工具">网络"时,在单击按钮之前,似乎没有注册,但是当我单击注册时,它并不能将我定向到任何地方.
When I click on the button nothing happens. When I check the Developer Tools > Network, before I click on the button, register doesn't seem however when I click it comes up but it doesn't direct me to anywhere.
当寄存器到达那里时,它还会在时间限制和initiator = Other
中显示一个长条.当我单击寄存器然后Preview
时,它说Failed to load response data
.你有什么主意吗?
When register comes there, it also shows a long bar in the timelime and initiator = Other
. When I click on register and then, Preview
it says Failed to load response data
. Do you have any idea?
- 我正在使用Laravel 5.1 + Laravel Collective
源代码:
<form method="POST" action="http://app.com/auth/register" accept-charset="UTF-8"><input name="_token" type="hidden" value="qq1exVYYTrmuRBrj62HGgOxJWidUK770lF5Wv1qH">
<input name="profession" type="hidden" value="writer">
<input class="btn btn-warning" type="submit" value="Writer">
</form>
- 当我单击Chrome开发者工具>源>源>
auth/register
时,出现错误(仅一次.其他时间未显示Sources
下的注册): - when I click on Chrome Developer Tools > Sources > Sources >
auth/register
, I got an error (only for one time. Other times are not showing register underSources
):
/p/home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php第53行中的TokenMismatchException:
TokenMismatchException in /home/vagrant/Code/Laravel/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php line 53:
推荐答案
这里发生了几件事.
除了我刚才在评论中提到的内容 (您正在注册两条在同一路径下执行不同操作的路由,即
Apart from what I mentioned just now in the comments (You are registering two routes that do different things under the same path, namely
Route::post('auth/register', [
'as' => 'writer_path',
'uses' => 'ProfessionController@displayForm'
]);
和
Route::post('auth/register', 'Auth\AuthController@postRegister');
) 这些文件共存于相同的routes.php文件中,如果网址相同,则可能会发生冲突
) These coexist in the same routes.php file and there might be conflicts if the urls are the same
此外,您的
public function displayForm()
{
$input = Input::get();
$profession = $input['profession'];
return view('auth/register', ['profession' => $profession]);
}
返回的是视图,路线,而不是说明中的命名路线:
is returning as a view, a route, not a named route like in the instructions:
public function displayForm()
{
$input = Input::get();
$profession = $input['profession'];
return view('writerregistration', ['profession' => $profession]);
}
正如我所说,这应该将您定向到将在名为writerregistration.blade.php的文件中创建的视图,在该视图中,应将代码以我在此处传递的形式放在答案的底部:
This, as I said should direct you to a view that you will create in a file called writerregistration.blade.php where you should put the code in the form that I passed here at the bottom of my answer:
这篇关于将变量从一个视图传递到另一个视图-Laravel 5.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!