如何在prestashop中将变量从控制器传递给控制器​​?

时间:2017-02-04 13:11:24

标签: php controller prestashop

有没有办法在prestashop中将变量从控制器传递到另一个?我想在AddressController覆盖上传递new_address变量,如下所示:

<body ng-app="testApp">
    <div ng-controller="testController">
      <div id="bla">
        <button ng-click="obey('bla')">Close</button>
        <h4>Bla bla bla</h4>
      </div>
    </div>
<body>

请注意,这是原始行+ Tools::redirect('index.php?controller='.$back.($mod ? '&back='.$mod : '') . '&new_address=' . $address->id); ,因此我必须坚持. '&new_address=' . $address->id

通过使用该行,$ _GET中的下一页上没有找到new_address。从OrderController和ParentOrderController,我也看不到它。

1 个答案:

答案 0 :(得分:0)

我在Tools :: redirect中找到了原因。它有这样的一行:

$url = Tools::strReplaceFirst('&', '?', $url); 

这里它们基本上排除了除第一个之外的任何查询变量,因此如果你添加一些,你将无法找到任何查询变量。如果您有index.php?a=1&b=2,则会获得index.php?a=1?b=2。我不明白这一点......也许这是一个错误。

所以我像这样覆盖了Tools :: redirect(修改过的行被注释):

public static function redirect($url, $base_uri = __PS_BASE_URI__, Link $link = null, $headers = null){
  if (!$link) $link = Context::getContext()->link;

  $querystring = array_pop(explode('?', $url)); // MOD: Save the original querystring. I take the last item in array because sometimes (i think it's a bug) the $url is like index.php?controller=order.php?step=1, so 2 question marks.

  if (strpos($url, 'http://') === false && strpos($url, 'https://') === false && $link) {
    if (strpos($url, $base_uri) === 0) {
      $url = substr($url, strlen($base_uri));
    }
    if (strpos($url, 'index.php?controller=') !== false && strpos($url, 'index.php/') == 0) {
      $url = substr($url, strlen('index.php?controller='));
      if (Configuration::get('PS_REWRITING_SETTINGS')) {
        $url = Tools::strReplaceFirst('&', '?', $url); // ...Don't see the point here...
      }
    }

    $explode = explode('?', $url);

    // don't use ssl if url is home page
    // used when logout for example
    $use_ssl = !empty($url);
    $url = $link->getPageLink($explode[0], $use_ssl);

    if($querystring) $url .= '?'.$querystring; // MOD: adding full querystring!! Also deleted 3 lines that added $explode[1] instead
  }

  // Send additional headers
  if ($headers) {
    if (!is_array($headers)) $headers = array($headers);

    foreach ($headers as $header) {
      header($header);
    }
  }

  header('Location: '.$url);
  exit;
}