【问题标题】:Return an iframe view from a controller function从控制器函数返回 iframe 视图
【发布时间】:2020-03-04 07:35:01
【问题描述】:

我是 Laravel 的新手。这是我在 SmartpayS 控制器中的功能。我想在 iframe 中返回这个 url。 $url = $item->nodeValue;

function processSmartpaySPayment($paymentType = false, $totalAmount = 0, $currency = false, $payingUserId = false, $quoteId = false, $clubMembershipQuotationId = false)
    {
        $callBackUrl = 'smartpays-payment/response/'.$quoteId;

        if (!empty($payingUserId)) {
            $customerDetails = $this->customerRepo->getCustomerDetails($payingUserId);

        } else {
            return false;
        }

        $testString = $this->smartPaySRepo->createSmartpaySPayment($paymentType, env('ENTERPRISE_ID'), 'DE02', 'ECommerce',env('AUTH_TYPE'), $totalAmount, $customerDetails, $currency, $callBackUrl, $quoteId, $clubMembershipQuotationId, env('STORE_RESULT_PAGE') );
        $dom = new \DOMDocument();
        $dom->formatOutput = TRUE;
        $dom->preserveWhiteSpace = FALSE;
        $dom->loadXml($testString);

        foreach ($dom->getElementsByTagName('redirectURL') as $item) {

           $url = $item->nodeValue;

        }

        return redirect($url);
}


----------


**********iframe is in the view.(paymentload.blade.php)*************


<iframe src="<?php echo $url; ?>" width="600px" height ="800px" ></iframe>


我尝试加载 iframe。但它说“未定义的变量:url” 帮我从控制器函数返回视图中的 iframe。

【问题讨论】:

    标签: php laravel iframe


    【解决方案1】:

    试试这个

    $url = '';
    foreach ($dom->getElementsByTagName('redirectURL') as $item) {
    
      $url = $item->nodeValue;
    }
    
     return redirect($url);
    

    我认为你每次都在添加 $item->nodeValue 所以你应该像这样使用

    $url = '';
    foreach ($dom->getElementsByTagName('redirectURL') as $item) {
    
      $url += $item->nodeValue; // check i have added + here 
    }
    
     return redirect($url);
    

    【讨论】:

    • 谢谢。 Undefined variable: url 问题解决了。但是,页面重定向到首页;不是我要重定向的页面。这是视图可用的路径。 web.php 中的路由应该是什么? app/Modules/Payment/Resources/Views/smartpay/paymentload.blade.php
    • 只需在返回之前输入dd($url) 并显示您得到了什么?
    猜你喜欢
    • 1970-01-01
    • 2013-01-08
    • 2017-02-13
    • 2020-02-18
    • 2015-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多