Opencart:无法使用$ this-> url->链接和curl调用控制器 [英] Opencart: Cannot call controller with $this->url->link and curl

查看:993
本文介绍了Opencart:无法使用$ this-> url->链接和curl调用控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cUrl来呼叫网页,如下所示:

I want to call a page using cUrl like this:

    $ch = curl_init();
    $timeout = 0; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, $this->url->link('account/order/invoice', 'order_id=20'));
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $invoice = curl_exec($ch);
    curl_close($ch);

这不起作用。 order_id = 20不传递到控制器。
这样工作:

This does not work. "order_id=20" is not passed through to the controller. This does work:

    $ch = curl_init();
    $timeout = 0; // set to zero for no timeout
    curl_setopt ($ch, CURLOPT_URL, 'http://webshop.local/index.php?route=account/order/invoice&order_id=20');
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
    $factuur = curl_exec($ch);
    curl_close($ch);



当我回显$ this-> url-> link('account / order / invoice' order_id = 20'),网址正确。

When I echo $this->url->link('account/order/invoice', 'order_id=20'), the URL is correct.

我没有看到任何差异。我可以使用第二个方法,但第一个更正确的在opencart中创建url。

I don't see any difference. I could use the second method, but the first is more correct for creating urls in opencart.

我想知道我做错了什么,为什么它这样工作。

I would like to know what I do wrong or why it works like this.

推荐答案

这样做的答案是网址不是同一

检查/system/url.php中的代码:

Check the code in /system/url.php:

if ($args) {
    $url .= str_replace('&', '&', '&' . ltrim($args, '&')); 
}

您生成的网址将是:

http://webshop.local/index.php?route = account / order / invoice& amp; order_id = 20

与您手写的相比:

http://webshop.local/index.php?route = account / order / invoice& order_id = 20

这是因为辅助工具设计为 / strong>,其中& amp; 将被正确解析。回到您生成的链接并查看页面源代码,或查看您的商店链接,您会看到我的意思。

That's because the helper is designed to output URLs intended for use in HTML, where the & will be correctly parsed. Echo out your generated link and view the page source, or look at your shop links and you'll see what I mean.

如果你挖得更深,看看顶部您将看到:

If you dig deeper and look at the top of the account/account controller, you'll see this:

$ this-> redirect($ this-> url->链接('account / login','','SSL'));

重定向助手(在system / engine / php)实际上必须将& amp; s 再次转换,才能使用由网址助手创建的网址:

The redirect helper (in system/engine/controller.php) actually has to convert the &s back again before it can use the URLs created by the URL helper:

header('Location:'。str_replace(array('& amp;',\\\
,\r),array '&','',''),$ url));

坦率地说,这有点乱,

Frankly, it's a bit of a mess, but that's what you have to work with.

所以如果你想使用URL helper,我建议你做同样的事情,OpenCart本身:

So if you want to use the URL helper, I suggest you do the same thing as OpenCart itself:

curl_setopt($ ch,CURLOPT_URL,str_replace('& amp;','&',$ this-> url-> link / invoice','order_id = 20')));

这篇关于Opencart:无法使用$ this-> url->链接和curl调用控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆