dousi1970 2014-03-23 12:14
浏览 39
已采纳

Laravel重定向不传递变量

I am creating a simple page to hash strings with md5, however the output is never returned.

This is the controller I use for these pages. The function md5 is routed to the get and the function md5post is routed to the post. The view has a form that is posted to the md5post function. it has one variable $input with the string to hash.

<?php

class ConversionsController extends \BaseController {

    private $withmd5;

    public function __construct(){
        $this->withmd5 = [
            'pagetitle' => 'MD5 hashing',
            'description' => 'description',
            'infoWindow' => 'info',
            'btnSumbit' => Form::submit('Hash', ['class' => 'btn btn-default'])
        ];
    }


    public function md5(){
        return View::make("layout.textareamaster")->with($this->withmd5);
    }
    public function md5post(){

        if (strlen(Input::get("input")) > 0)
        {
            $hash = md5(Input::get("input"));
        }

        return Redirect::back()->withInput()->with("output", $hash);
    }

}

And this is the view

{{ Form::open(['method' => 'post']) }}
    <div class="row">
        <div class="col-md-6">
            <p class="well">
                {{ Form::textarea('input', '', ['class' => 'form-control', 'rows' => 5]) }}
                <span style="float:right;">
                    {{ $btnSubmit or Form::submit('Go', ['class' => 'btn btn-default']) }}
                </span>
            </p>
        </div>
        <div class="col-md-6">
            <p class="well">
                <textarea class="form-control" rows="5" readonly="true">{{ $output or "nothing" }}</textarea>
            </p>
        </div>
    </div>
{{ Form::close() }}

When in my template file, the input is always displayed, however, the variable $output is always undefined. I have beent trying to use other variable names, but it wont work.

If I return the variable right before the redirect, I see the correct output.

  • 写回答

1条回答 默认 最新

  • doushou7169 2014-03-23 15:22
    关注

    I have found a solution. In my view I had to use Session::get() to get the value.

    That still didn't return the correct output, but I got it by casting this variable to string.

    My solution:

    {{ (string)Session::get('output') }}
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测