0

我正在编写一个辅助函数来共享视图的负载,因为它可以在某些页面上被多次调用。唯一的问题是它有时只能工作,但所有相关文件都在那里,并且 Code Igniter 不会生成错误消息。这是调用该函数的视图:

        <div id="newProducts" class="floatLeft">
        <div class="titleBar">
            <h4>New Product Arrivals</h4>
        </div>
<?php foreach($newProducts as $product) :
        loadshareProductPreview($product);
endforeach; ?>

这是到目前为止的功能:

function loadShareProductPreview($product)
{

$time = microtime(true);

if($time % 3 == 0)
{

    include("/home/client/library/application/views/widgets/productPreview.php");

}
elseif($time % 3 == 1)
{

    include("/home/client/library/application/views/widgets/productPreviewLS1.php");

}
elseif($time % 3 == 2)
{

    include("/home/client/library/application/views/widgets/productPreviewLS2.php");

}

}

关于如何让它一直加载的任何想法?

4

1 回答 1

0

在遵循评论中的建议后,我创建了一个函数来替换 incude() 。这是代码:

<?php
function loadShareProductPreview($product)
{

    $time = microtime(true);

    if($time % 3 == 0)
    {

        load_view("widgets/productPreview", $product);

    }
    elseif($time % 3 == 1)
    {

        load_view("widgets/productPreviewLS1", $product);

    }
    elseif($time % 3 == 2)
    {

        load_view("widgets/productPreviewLS2", $product);

    }

}

function load_view($view, $vars = '', $return = FALSE)
{

  $CI =& get_instance();
  return $CI->load->view($view, $vars, $return);
}
于 2012-05-25T13:50:54.423 回答