久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Laravel 將數據從一個視圖傳遞到另一個視圖

Laravel Passing Data From One View to Another View(Laravel 將數據從一個視圖傳遞到另一個視圖)
本文介紹了Laravel 將數據從一個視圖傳遞到另一個視圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在考慮從主頁制作一個登陸頁面,將訪客引導至注冊頁面.我想制作兩個用于發送數據的表單和其中的兩個提交按鈕,比如說讀寫器,根據他們用來進入注冊表單頁面的按鈕,我想傳遞 profession 字符串從登錄頁面中的按鈕,然后將其放入 /auth/register 中的注冊表中.

I am thinking of making a landing page from the home page, which will direct the guest to the register page. I thought of making two forms for sending data and two submit buttons in them, let's say reader and writer and according to the button they use to go to the register form page, I want to pass the profession string from the button in the landing page and then, place it into the register form in /auth/register.

    {!! Form::open(array('url' => '/auth/register', 'profession' => 'writer')) !!}

    {!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}

    {!! Form::close() !!}


    {!! Form::open(array('url' => '/auth/register', 'profession' => 'reader')) !!}

    {!! Form::submit('Reader', array('class' => 'btn btn-default')) !!}

    {!! Form::close() !!}

它沒有將我引導至頁面 app.com/auth/register.但是當我直接輸入鏈接時它會起作用.

It is not directing me to the page app.com/auth/register. But it works when I directly type the link.

我認為在 /auth/register/ 中使用 $profession 并訪問該值并將其用作注冊表中的隱藏字段.

What I thought was using $profession in /auth/register/ and access the value and use it as a hidden field in the registeration form.

(使用 laravel 5.1)

(using laravel 5.1)

查看源代碼:

    <form method="POST" action="http://app.com/auth/register" accept-charset="UTF-8" profession="writer"><input name="_token" type="hidden" value="dZXQsNI1BGQ39JjDLFUEkSQzL5bTNwe8o3rpiSQL">

    <input class="btn btn-warning" type="submit" value="Writer">

    </form>


    <form method="POST" action="http://app.com/auth/register" accept-charset="UTF-8" profession="reader"><input name="_token" type="hidden" value="dZXQsNI1BGQ39JjDLFUEkSQzL5bTNwe8o3rpiSQL">

    <input class="btn btn-default" type="submit" value="Reader">

    </form>

<小時>

編輯 2:

    {!! Form::open(array('url' => '/auth/register', 'profession' => 'writer')) !!}

    {!! link_to('/auth/register', 'Writer', array('class' => 'btn btn-default')) !!}

    {!! Form::close() !!}

我嘗試了這個.至少,現在它正在引導頁面,但我仍然無法訪問profession

I tried this instead. At least, now it is directing the page but I still can't access the data value of profession

編輯 3:

路線:

Route::get('auth/register', 'AuthAuthController@getRegister');
Route::post('auth/register', 'AuthAuthController@postRegister');

Route::get('/', function()
{
    return view('pages.home');
});

https://app.com/auth/register 正在工作.

推薦答案

以下是有關如何實施它的分步演練.我測試了它.所以它有效.這是給作家"的,但您可以按照原先計劃用于其他職業的方式復制它.

Here's a step by step walkthrough on how to implement it. I tested it. So it works. This is for 'writer', but you could replicate it as you had originally planned for other professions.

我假設您已經注冊了 Laravel Collective 包,因為您使用的是花括號和感嘆號.

I assume you've registered the Laravel Collective package since you're using the curly braces and exclamation points.

第 1 步:

在您的著陸頁視圖中,您有作家按鈕的位置,添加一個帶有字符串作家"的隱藏字段.像這樣:

In your landing page view, where you have the writer button, add a hidden field with the string 'writer'. Like this:

{!! Form::open(['route' => ['writer_path']]) !!}
{!! Form::hidden('profession', 'writer') !!}
{!! Form::submit('Writer', array('class' => 'btn btn-warning')) !!}
{!! Form::close() !!}

并不是說在開放字段中我們使用的是命名路線('writer_path').

Not that in the open field we are using a named route ('writer_path').

第 2 步:

在你的 routes.php 文件中注冊一個路由和一個控制器,像這樣:

Register a route and a controller on your routes.php file, like this:

Route::post('auth/register', [
'as' => 'writer_path',
'uses' => 'SampleController@displayForm'
]);

第 3 步:

在您的示例控制器中,您定義了 displayForm 方法.在該方法中,您首先獲取從著陸頁視圖傳遞的值.

In your sample controller, you define the displayForm method. Within that method you first obtain the value you passed from the landing page view.

如果你不知道如何創建一個控制器,你可以做

If you don't know how to create a controler, you can do

php artisan make:controller SampleController

從命令行

因為該值是作為數組到達的,所以您必須從數組中獲取字符串writer",然后將其傳遞給新視圖(帶有 writer 注冊表的視圖).

Because the value arrives as an array, you have to obtain the string 'writer' from the array and then pass it to the new view (the view with the registration form for the writer).

<?php

namespace AppHttpControllers;
use IlluminateHttpRequest;
use AppHttpRequests;
use AppHttpControllersController;
use IlluminateSupportFacadesInput;

class SampleController extends Controller
{
/**
 * Display a listing of the resource.
 *
 * @return Response
 */
public function displayForm()
{
    $input = Input::get();
    $profession = $input['profession'];
    return view('writerregistration', ['profession' => $profession]);
}

}

最后一步:

在您將創建為 writerregistration.blade.php 的新視圖中,您將顯示包含您剛剛傳遞的字段 ('profession') 的表單,該字段包含字符串 'writer'.像這樣:

In the new view which you will create as writerregistration.blade.php, you will display the form with the field you just passed ('profession') which contains the string 'writer'. Like this:

{!! Form::open() !!}

{!! Form::label('username', 'Username:') !!}
{!! Form::text('username', null, ['class' => 'form-control']) !!}

{!! Form::label('profession', 'Profession:') !!}
{!! Form::text('profession', $profession, ['class' => 'form-control']) !!}

{!! Form::label('email', 'Email:') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}

{!! Form::label('passowrd', 'Password:') !!}
{!! Form::password('password', ['class' => 'form-control']) !!}  

{!! Form::label('password_confirmation', 'Password Confirmation:') !!}
{!! Form::password('password_confirmation', ['class' => 'form-control']) !!}

{!! Form::submit('Sign Up', ['class' => 'btn btn-primary']) !!}

{!! Form::close() !!}

Presto,您已經在作者的注冊表中填寫了該字段,其中包含屬于著陸頁中作者按鈕的隱藏字段的信息.

Presto, you've populated the field in the registration form for the writer with the info on the hidden field that belonged to the writer button in the landing page.

這篇關于Laravel 將數據從一個視圖傳遞到另一個視圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Magento products by categories(按類別劃分的 Magento 產品)
Resource interpreted as image but transferred with MIME type text/html - Magento(資源被解釋為圖像但使用 MIME 類型 text/html 傳輸 - Magento)
Is there an event for customer account registration in Magento?(Magento 中是否有客戶帳戶注冊事件?)
Magento addFieldToFilter: Two fields, match as OR, not AND(Magento addFieldToFilter:兩個字段,匹配為 OR,而不是 AND)
quot;Error 404 Not Foundquot; in Magento Admin Login Page(“未找到錯誤 404在 Magento 管理員登錄頁面)
Get Order Increment Id in Magento(在 Magento 中獲取訂單增量 ID)
主站蜘蛛池模板: 欧美亚洲第一区 | 亚洲一区二区电影网 | 天天操夜夜拍 | 一区二区三区精品 | 精品乱码一区二区 | 五月婷婷激情网 | 色综合一区二区三区 | 国产又爽又黄的视频 | 成人深夜福利在线观看 | 丝袜美腿一区二区三区动态图 | 欧美日本久久 | 精品成人在线观看 | 天天色综| 久久免费香蕉视频 | 在线看片福利 | 精品国产一区二区国模嫣然 | 日韩欧美三区 | 欧美一区二区三区日韩 | 久久天天躁狠狠躁夜夜躁2014 | 国产一区二区三区在线 | 国产免费观看一级国产 | 91动漫在线观看 | 国产日韩欧美在线 | 午夜影院在线观看视频 | 久久国产成人 | 免费在线观看黄色av | 欧美1区 | 国产午夜精品久久久久 | 欧美日韩综合精品 | 国产精品99久久免费观看 | 精品久久精品 | 激情毛片 | 成人九色| 亚洲一区二区三区在线 | 亚洲久在线| 久久久入口 | 亚洲日韩第一页 | ww 255hh 在线观看 | 欧美性video| 亚洲一区二区在线 | 午夜理伦三级理论三级在线观看 |