代码之家  ›  专栏  ›  技术社区  ›  ALJ

在Laravel 4.2中,如何将字符串回显到视图中?

  •  0
  • ALJ  · 技术社区  · 7 年前

    artisan 来自控制器的命令,返回重定向回。

    echo 一些东西对我来说(当我从终端调用它时,这很有帮助),但现在因为我在方法中使用它,我想要同样的东西 echos 在我的视图中显示为flash消息。

    public function fire()
    { 
        // Do stuff.
        echo $vars 
    }
    

    我的控制器:

    function foo() {
    
          // Some input here
    
          Artisan::call('command');
    
    
          return Redirect::back(); // <-- want to add the echos of the command. 
    }
    

    所以我想展示 $var 在我看来,我不确定是否有可能,如果没有,我愿意接受其他可以给我相同概念的建议(请记住,如果我替换 回响

    注意:我尝试了Ajax,但我的问题是以param形式发送文件,尝试了FormData对象,但它对我不起作用。

    2 回复  |  直到 7 年前
        1
  •  2
  •   Devon Bessemer    7 年前

    在会话中存储数据是在多个请求中保持持久数据的好方法。会话闪烁是一种仅为下一个请求保留数据的方法,非常适合重定向。当存在验证错误时,Laravel在内部将其用于旧输入数据。

    https://laravel.com/docs/4.2/session#flash-data

    Session::flash('key', 'value');
    

    这将只保留在下一个请求中,您可以在其中使用 Session::get('key')

        2
  •  0
  •   ALJ    7 年前

    命令:

    function fire()
    {
      // replaced the echo with the following.
      $this->info('what ever you want ur message you want to put in console');
    
     }
    

    控制器

    function foo()
    {
    
      $output =  new BufferedOutput();
    
      Artisan::call('command', [arguments], $output);
    
      return Redirect::back()->with('flash_message', $output->fetch());
    }
    

    Laravel Documentations echo's