如何将变量传递给Laravel中的控制器进行查看

时间:2016-06-13 11:33:43

标签: php view laravel-4

当用户下订单时,它会将他重定向到另一个页面,检查他是否付款或不付款。现在控制器已准备好,我需要初始化这个框,我需要采取一些变量..我不知道如何实现这个到payment.blade.php。这是我尝试过的,似乎没有用。

这是控制器

public function paymentView( $orderId, $userId ) {

    $order = Session::all();

    $order = Order::where('order_id', $orderId)->first();

    if (!$order) {
        App::abort(404);
    }


    $userID         = $order['user_id'];                        
    $orderID        = $order['order_id'];           

    $options = array(
        ...
    );

    // Initialise Payment Class
    $box = new Cryptobox ($options);

    // coin name
    $coinName = $box->coin_name(); 

    // Successful Cryptocoin Payment received
    if ($box->is_paid()) 
    {
        if (!$box->is_confirmed()) {
            $message =  "Thank you for payment (payment #".$box->payment_id()."). Awaiting transaction/payment confirmation";
        }                                           
        else 
        { 

            if (!$box->is_processed())
            {

                $message = "Thank you for order (order #".$orderID.", payment #".$box->payment_id()."). We will send soon";

                $box->set_status_processed();  
            }
            else $message = "Thank you. Your order is in process"; // General message
        }
    }
    else $message = "This invoice has not been paid yet";

    $languages_list = display_language_box($def_language);

    return View::make('site.cart.payment', [
                'order' => $order,
    ]); 
}

现在我想把它放在我看来

@section('content')
  @foreach($order->getOrderData(true) as $productId => $item)
     <?php if (!$box->is_paid()) echo "<h2>Pay Invoice Now - </h2>"; else echo "<br><br>";  ?>

     <?php echo $box->display_cryptobox(true, 580, 230); ?>
  @endforeach
@endsection

当我运行页面时,我遇到错误box未定义..如何在视图中显示此信息?

1 个答案:

答案 0 :(得分:0)

以同样的方式将$order传递给视图。使用此返回值替换方法底部的return

return View::make('site.cart.payment', [
    'order' => $order,
    'box' => $box
]); 

传递给View::make()的第二个参数是应该可供视图使用的数据数组。