duanjue2576 2012-10-18 13:43
浏览 7
已采纳

too long

I have a foreach statement that looks like the following:

foreach ($term['terms'] as $term_single) {
    $term_object = get_term_by('name', $term_single, $tax_name);

    switch ($term['tax_name']) {
        case has_action( "basey_taxonomy_search_teaser_{$tax_name}" ) :
            do_action( "basey_taxonomy_search_teaser_{$tax_name}",$term_object, $term_single );
        break;

        default:
            echo basey_taxonomy_search_teaser_default($term_object,$term_single);
        break;
    }
}

So, within this, I have both the $term_object and $term_single variables to pass to the basey_taxonomy_search_teasr_default() function. The odd thing here is, if I do the following in another location:

function basey_taxonomy_search_teaser_default($term_object,$term_single) {

    ob_start();

    do_action('basey_taxonomy_teaser_before');
    echo '<article id="tax-' . $term_object->term_id . '" class="' . $term_object->taxonomy . '">';
    echo '<a href="';
    echo get_term_link($term_object);
    echo '">';
    echo $term_single;
    echo '</a>';
    echo '</article>';
    do_action('basey_taxonomy_teaser_after');

    $display = apply_filters('basey_taxonomy_teaser_default_view', ob_get_clean());
    return $display;
}

it works just fine on my localhost, but online at a server, it is coming back with errors for $term_object and $term_single as undefined. If I want the function definition to use the values from the initial call, is there a better way to do so? Again little confused on why it would work here on localhost (MAMP) but on the server, it would error out. Aside from it being a php.ini issue (which I think this is more fundamental programming practice), looking to see what I'm doing wrong and if my assumptions are off on passing values via a function. Thanks!

Update

var_dump($term_object) right after $term_object = get_term_by('name', $term_single, $tax_name);:

localhost gives me:

object(stdClass)#181 (10) { ["term_id"]=> string(3) "127" ["name"]=> string(4) "Base" ["slug"]=> string(4) "base" ["term_group"]=> string(1) "0" ["term_order"]=> string(1) "0" ["term_taxonomy_id"]=> string(3) "130" ["taxonomy"]=> string(18) "profile_categories" ["description"]=> string(4) "Base" ["parent"]=> string(1) "0" ["count"]=> string(1) "2" }

live server gives me:

bool(false)

Bah, quite frustrating.

  • 写回答

2条回答 默认 最新

  • dongtang1966 2012-10-18 13:47
    关注

    I'd guess that the DB you're hitting is different and the $term_single is null, leading to a null $term_object, and when you call the function and try to use the objects that's where you're dying.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥100 已有python代码,要求做成可执行程序,程序设计内容不多
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答