Php ExpressionEngine:如何在给定页面条目id的情况下获取页面的路径(使用结构插件)

Php ExpressionEngine:如何在给定页面条目id的情况下获取页面的路径(使用结构插件),php,structure,expressionengine,Php,Structure,Expressionengine,我正在尝试构建一个扩展,该扩展将为短URL的自动重定向创建页面,为了使其简短,我需要获得给定其入口id的页面路径 例如,我有一个页面,其中包含以下路径: 但是,在代码中,我只知道这个页面的条目id 如果我查看exp\u channel\u titles表,我可以得到url\u title字段。但它将只包含“页面”。我想获得“/path/to/my/page”。而且似乎没有任何用于此的API 你知道我该怎么做吗 非常感谢。我没有找到比以下代码更好的代码: // // // Don't

我正在尝试构建一个扩展,该扩展将为短URL的自动重定向创建页面,为了使其简短,我需要获得给定其入口id的页面路径

例如,我有一个页面,其中包含以下路径: 但是,在代码中,我只知道这个页面的条目id

如果我查看exp\u channel\u titles表,我可以得到url\u title字段。但它将只包含“页面”。我想获得“/path/to/my/page”。而且似乎没有任何用于此的API

你知道我该怎么做吗


非常感谢。

我没有找到比以下代码更好的代码:

  //
  //
  // Don't look the following code just yet . . .
  //
  //
  // You'll be pulling your hair out of your head. Just read me first.

  // Following is a huge SQL query, that assume that pages are not nested
  // than 9 times. This is actually a hard limitation of EE, and I'm using
  // that to get the information I need in only one query instead of nine.
  //
  // The following code is just to get the path of the current entry we are
  // editing, so the redirect page will know where to redirect. And I did
  // not find any function or API to get this information. Too bad.
  //
  // If you find any solution to that, please answer
  // http://stackoverflow.com/questions/8245405/expressionengine-how-to-get-the-path-of-a-page-given-its-entry-id-with-the-str
  // it might save other people all the trouble.

  // S
  //
  // P
  //
  // O
  //
  // I
  //
  // L
  //
  // E
  //
  // R

  // First, we get all the entry_id of all the elements that are parent to
  // the current element in the structure table (created by the Structure
  // plugin).

  $q = $this->EE->db->query(
    "SELECT
      S1.entry_id AS entry9,
      S2.entry_id AS entry8,
      S3.entry_id AS entry7,
      S4.entry_id AS entry6,
      S5.entry_id AS entry5,
      S3.entry_id AS entry4,
      S7.entry_id AS entry3,
      S8.entry_id AS entry2,
      S9.entry_id AS entry1
    FROM
      exp_structure AS S1,
      exp_structure AS S2,
      exp_structure AS S3,
      exp_structure AS S4,
      exp_structure AS S5,
      exp_structure AS S6,
      exp_structure AS S7,
      exp_structure AS S8,
      exp_structure AS S9
    WHERE
      S1.entry_id = $entry_id AND
      S1.parent_id = S2.entry_id AND
      S2.parent_id = S3.entry_id AND
      S3.parent_id = S4.entry_id AND
      S4.parent_id = S5.entry_id AND
      S5.parent_id = S6.entry_id AND
      S6.parent_id = S7.entry_id AND
      S7.parent_id = S8.entry_id AND
      S8.parent_id = S9.entry_id");

  // Then, we construct a similar query to get all the url_title attributes
  // for these pages.

  $path = array();
  $sql = array("SELECT" => "SELECT", "FROM" => " FROM", "WHERE" => " WHERE");
  $j = 1;
  for($i = 1; $i <= 9; ++$i){
    $id = $q->row("entry$i");
    if($id > 0){
      $sql['SELECT'] .= " CT$j.url_title AS title$j,";
      $sql['FROM']   .= " exp_channel_titles as CT$j,";
      $sql['WHERE']  .= " CT$j.entry_id = $id AND";
      $j++;
    }
  }
  $sql['SELECT'] = rtrim($sql['SELECT'], ",");
  $sql['FROM']   = rtrim($sql['FROM'], ",");
  $sql['WHERE'] = preg_replace("/ AND$/", "", $sql['WHERE']);
  $sql = $sql['SELECT'] . $sql['FROM'] . $sql['WHERE'];
  $q = $this->EE->db->query($sql);

  // Finally, we can construct the path for the current page

  $path = "/";
  for($i = 1; $i < $j; ++$i){
    $path .= $q->row("title$i") . '/';
  }

  //
  // Blood and bloody ashes.
  //
//
//
//现在不要查看下面的代码。
//
//
//你会把头发从脑袋里拔出来的。先念给我听。
//下面是一个巨大的SQL查询,它假设页面没有嵌套
//超过9倍。这实际上是EE的一个硬限制,我正在使用
//我只需要在一个查询中而不是在九个查询中获得所需的信息。
//
//下面的代码只是为了获取当前条目的路径
//编辑,这样重定向页面将知道重定向到哪里。我做到了
//找不到任何函数或API来获取此信息。太糟糕了。
//
//如果你能找到解决办法,请回答
// http://stackoverflow.com/questions/8245405/expressionengine-how-to-get-the-path-of-a-page-given-its-entry-id-with-the-str
//这可能会省去别人所有的麻烦。
//
//
//P
//
//O
//
//我
//
//L
//
//E
//
//R
//首先,我们获取作为父元素的所有元素的所有entry_id
//结构表中的当前元素(由结构创建)
//插件)。
$q=$this->EE->db->query(
“选择
S1.入口id作为入口9,
S2.入口id作为入口8,
S3.入口id作为入口7,
S4.入口id作为入口6,
S5.入口标识为入口5,
S3.入口id作为入口4,
S7.入口id作为入口3,
S8.入口标识为入口2,
S9.入口id作为入口1
从…起
exp_结构为S1,
exp_结构为S2,
exp_结构为S3,
exp_结构为S4,
exp_结构为S5,
exp_结构为S6,
exp_结构为S7,
exp_结构为S8,
exp_结构为S9
哪里
S1.entry\u id=$entry\u id和
S1.parent\u id=S2.entry\u id和
S2.parent\u id=S3.entry\u id和
S3.parent_id=S4.entry_id和
S4.家长id=S5.进入id和
S5.家长id=S6.进入id和
S6.家长id=S7.入学id和
S7.家长id=S8.入口id和
S8.父项id=S9.条目id”);
//然后,我们构造一个类似的查询来获取所有url\u标题属性
//对于这些页面。
$path=array();
$sql=array(“选择”=>“选择”、“从”=>“从”、“其中”=>“其中”);
$j=1;
对于($i=1;$i行(“条目$i”);
如果($id>0){
$sql['SELECT'].=“CT$j.url_title作为title$j,”;
$sql['FROM']。=“exp_channel_titles as CT$j,”;
$sql['WHERE'].=“CT$j.entry\u id=$id和”;
$j++;
}
}
$sql['SELECT']=rtrim($sql['SELECT'],“,”);
$sql['FROM']=rtrim($sql['FROM'],“,”);
$sql['WHERE']=preg_replace(“/和$/”,“”,$sql['WHERE']);
$sql=$sql['SELECT'].$sql['FROM'].$sql['WHERE'];
$q=$this->EE->db->query($sql);
//最后,我们可以为当前页面构造路径
$path=“/”;
对于($i=1;$i<$j;++$i){
$path.=$q->行(“标题$i”)。/;
}
//
//血和血灰。
//

我没有找到比以下代码更好的代码:

  //
  //
  // Don't look the following code just yet . . .
  //
  //
  // You'll be pulling your hair out of your head. Just read me first.

  // Following is a huge SQL query, that assume that pages are not nested
  // than 9 times. This is actually a hard limitation of EE, and I'm using
  // that to get the information I need in only one query instead of nine.
  //
  // The following code is just to get the path of the current entry we are
  // editing, so the redirect page will know where to redirect. And I did
  // not find any function or API to get this information. Too bad.
  //
  // If you find any solution to that, please answer
  // http://stackoverflow.com/questions/8245405/expressionengine-how-to-get-the-path-of-a-page-given-its-entry-id-with-the-str
  // it might save other people all the trouble.

  // S
  //
  // P
  //
  // O
  //
  // I
  //
  // L
  //
  // E
  //
  // R

  // First, we get all the entry_id of all the elements that are parent to
  // the current element in the structure table (created by the Structure
  // plugin).

  $q = $this->EE->db->query(
    "SELECT
      S1.entry_id AS entry9,
      S2.entry_id AS entry8,
      S3.entry_id AS entry7,
      S4.entry_id AS entry6,
      S5.entry_id AS entry5,
      S3.entry_id AS entry4,
      S7.entry_id AS entry3,
      S8.entry_id AS entry2,
      S9.entry_id AS entry1
    FROM
      exp_structure AS S1,
      exp_structure AS S2,
      exp_structure AS S3,
      exp_structure AS S4,
      exp_structure AS S5,
      exp_structure AS S6,
      exp_structure AS S7,
      exp_structure AS S8,
      exp_structure AS S9
    WHERE
      S1.entry_id = $entry_id AND
      S1.parent_id = S2.entry_id AND
      S2.parent_id = S3.entry_id AND
      S3.parent_id = S4.entry_id AND
      S4.parent_id = S5.entry_id AND
      S5.parent_id = S6.entry_id AND
      S6.parent_id = S7.entry_id AND
      S7.parent_id = S8.entry_id AND
      S8.parent_id = S9.entry_id");

  // Then, we construct a similar query to get all the url_title attributes
  // for these pages.

  $path = array();
  $sql = array("SELECT" => "SELECT", "FROM" => " FROM", "WHERE" => " WHERE");
  $j = 1;
  for($i = 1; $i <= 9; ++$i){
    $id = $q->row("entry$i");
    if($id > 0){
      $sql['SELECT'] .= " CT$j.url_title AS title$j,";
      $sql['FROM']   .= " exp_channel_titles as CT$j,";
      $sql['WHERE']  .= " CT$j.entry_id = $id AND";
      $j++;
    }
  }
  $sql['SELECT'] = rtrim($sql['SELECT'], ",");
  $sql['FROM']   = rtrim($sql['FROM'], ",");
  $sql['WHERE'] = preg_replace("/ AND$/", "", $sql['WHERE']);
  $sql = $sql['SELECT'] . $sql['FROM'] . $sql['WHERE'];
  $q = $this->EE->db->query($sql);

  // Finally, we can construct the path for the current page

  $path = "/";
  for($i = 1; $i < $j; ++$i){
    $path .= $q->row("title$i") . '/';
  }

  //
  // Blood and bloody ashes.
  //
//
//
//现在不要查看下面的代码。
//
//
//你会发疯的,先念给我听。
//下面是一个巨大的SQL查询,它假设页面没有嵌套
//这实际上是EE的一个硬限制,我正在使用
//我只需要在一个查询中而不是在九个查询中获得所需的信息。
//
//下面的代码只是为了获取当前条目的路径
//编辑,这样重定向页面就会知道重定向到哪里。我做到了
//找不到任何函数或API来获取此信息。太糟糕了。
//
//如果你能找到解决办法,请回答
// http://stackoverflow.com/questions/8245405/expressionengine-how-to-get-the-path-of-a-page-given-its-entry-id-with-the-str
//这可能会省去别人所有的麻烦。
//
//
//P
//
//O
//
//我
//
//L
//
//E
//
//R
//首先,我们获取作为父元素的所有元素的所有entry_id
//结构表中的当前元素(由结构创建)
//插件)。
$q=$this->EE->db->query(
“选择
S1.入口id作为入口9,
S2.入口id作为入口8,
S3.入口id作为入口7,
S4.入口id作为入口6,
S5.入口标识为入口5,
S3.入口id作为入口4,
S7.入口id作为入口3,
S8.入口标识为入口2,
S9.入口id作为入口1
从…起
exp_结构为S1,
exp_结构为S2,
exp_结构为S3,
exp_结构为S4,
exp_结构为S5,
exp_结构为S6,
exp_结构为S7,
exp_结构为S8,
exp_结构为S9
哪里
S1.entry\u id=$entry\u id和
S1.parent\u id=S2.entry\u id和
S2.parent\u id=S3.entry\u id和
S3.parent_id=S4.entry_id和
S4.家长id=S5.进入id和
S5.家长id=S6.进入id和
S6.家长id=S7.入学id和
S7.家长id=S8.入口id和
S8.父项id=S9.条目id”);
//然后,我们构造一个类似的查询来获取所有url\u标题属性
//对于这些页面。
$path=array();
$sql=array(“选择”=>“选择”、“从”=>“从”、“其中”=>“其中”);
$j=1;
对于($i=1;$i行(“条目$i”);
如果($id>0){
$sql['SELECT'].=“CT$j.url_title作为title$j,”;
$sql['FROM']。=“exp_channel_titles as CT$j,”;
$sql['WHERE'].=“CT$j.entry\u id=$id和”;
$j++;
}