【问题标题】:Expressionengine PHP calling表达式引擎 PHP 调用
【发布时间】:2013-02-20 11:46:02
【问题描述】:

我编写了以下 PHP 函数,用于根据段 3 URL 返回当前类别。

<?php
 $this->EE =& get_instance();
 $seg3 = $this->EE->uri->segment(3);
 $categoriess = getCategory($seg3);

function getCategory($string)
   {
     switch ($string)
       {
         case "test1": return '16';
         case "test2": return '52';
         case "test3": return '18';
         case "test4": return '29';
         case "test5": return '37';
       }
     return '11';
   }
 ?>
 <?php echo $categoriess; ?>

好吧,该函数完成了这项工作并返回了正确的数字。问题在于调用类别标签中返回的数字。

{exp:channel:entries channel=“news” dynamic=“no” category=”<?php echo $categoriess; ?>” orderby=“entry_date” disable=“member_data|trackbacks” sort=“desc” limit=“5”}

在我看来一切都是正确的,但它就是行不通…… 非常感谢您的帮助!

谢谢!

【问题讨论】:

  • Wtf 是那些引号? “test5”, ‘37’?像这样写:case "test5": return 37;
  • 语法错误,如果我从返回中删除引号会出现意外的 T_LNUMBER
  • 从什么时候返回通常的整数应该是错误的?

标签: php tags categories expressionengine


【解决方案1】:

检查您的解析顺序:在模板首选项中将“PHP Parsing Stage”设置为“Input”。

默认设置是“输出”,如果您想从 EE 短代码中获取值 并将其作为变量提供给 PHP,则该设置非常有效。

但在这种情况下,您想在 PHP 中运行一个函数,然后将返回值“馈入” EE。

所以在这种情况下,EE 将从 PHP 获取“输入”,这意味着 Preferences 下的 PHP Parsing Stage 用于特定模板 (不是一般偏好或其他任何地方)必须设置为 Input

我现在看到这是一个老问题,但我希望无论如何有人会使用这个答案。如果我想先检查解析顺序,我只是浪费了一整天的时间来做一些不到 5 分钟的事情。

【讨论】:

    【解决方案2】:
    <?php
        function getCategory($string)
        {
             $data = array(
               "test1" => 16,
               "test2" => 52,
               "test3" => 18,
               "test4" => 29,
               "test5" => 37
             ) ;
             return (isset($data[$string])) ? $data[$string] : 11 ;
         }
       $this->EE =& get_instance();
       $seg3 = $this->EE->uri->segment(3);
       $categoriess = getCategory($seg3);
    ?>
    

    【讨论】:

    • 同样的问题。返回编号的空白页。
    • 你想展示什么?
    • 一个页面的内容。整个事情是基于 if category = test1 then 只显示该类别的条目。我有一个显示主类别的索引页面,但如果 url 像 index/maincateogory/test1 仅显示 test1 类别的条目
    • 更新了代码,再试一次。否则,我真的无法帮助你。
    • 没有帮助。无论如何,谢谢 Jari。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-02
    相关资源
    最近更新 更多