Jer*_*dev 0 php controller laravel
我正在创建一个简单的页面来使用md5散列字符串,但是永远不会返回输出.
这是我用于这些页面的控制器.函数md5被路由到get,函数md5post被路由到post.该视图具有发布到md5post函数的表单.它有一个变量$ input,带有要散列的字符串.
<?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);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是观点
{{ 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() }}
Run Code Online (Sandbox Code Playgroud)
在我的模板文件中,始终显示输入,但是,变量$ output始终是未定义的.我试图使用其他变量名称,但它不会工作.
如果我在重定向之前返回变量,我会看到正确的输出.
我找到了解决方案.在我看来,我不得不Session::get()用来获取价值.
那仍然没有返回正确的输出,但我通过将此变量转换为字符串来获得它.
我的解决方案
{{ (string)Session::get('output') }}
Run Code Online (Sandbox Code Playgroud)