Joomla会话变量和检索错误的值

时间:2012-01-02 18:53:51

标签: php session joomla

我正在为使用jReviews的Joomla安装做一些自定义编码。 在我的主页上的模块中,我将内容id的数组传递给会话变量(步骤1),然后在其他页面中,例如Top Products或Special Offers,我可能会向同一个会话变量发送一组不同的值(步骤2) ),每次这些值与某些属性相关时,就像“相关产品”功能。当我最终查看产品时,我应该获取在步骤2中发送的值,而是从第1步获取值。

这就是我正在做的事情:

第1步:

$db =& JFactory::getDBO();
$query = "select * from jos_jreviews_content jrc 
join jos_content jc on jrc.contentid = jc.id 
where jc.state=1 and jc.catid=10 order by jc.id desc limit 100";
//state 1= published, catid 10= products, 
$db->setQuery($query);
$allproducts = $db->loadObjectList(); 
$nav_session = JFactory::getSession();
$nav_listings_ids = array();

if(count($allproducts)) {
    $i=0;

    foreach($allproducts as $relatedproduct) {
        $listingid = $relatedproduct->id;
        $alias = $relatedproduct->alias;
        $nav_listings_ids[$i]["id"] = $relatedproduct->contentid;
        $nav_listings_ids[$i]["link"] = "index.php?option=com_content&view=article&catid=10:products&id=".$listingid.":".$alias."&Itemid=16";
        $nav_listings_ids[$i]["title"] = $relatedproduct->title;
        $i++;
    }
}

// Save to session var 
$nav_session->set('related_results_listings', $nav_listings_ids);

第2步:

$jrcompanyname = '*'.$listing['Field']['pairs']['jr_companyname']['value'][0].'*';

$db =& JFactory::getDBO();
$query = "select * from jos_jreviews_content jrc 
join jos_content jc on jrc.contentid = jc.id 
where jrc.jr_companyname = '".$jrcompanyname."' and jc.state=1 and jc.catid=10 order by jrc.contentid desc";
$db->setQuery($query);
$relatedproducts = $db->loadObjectList(); 

$nav_session = JFactory::getSession();

$nav_listings_ids = array();

if(count($relatedproducts)) {
    $i=0;

    foreach($relatedproducts as $relatedproduct) { 
        $listingid = $relatedproduct->id;
        $alias = $relatedproduct->alias;
        $nav_listings_ids[$i]["id"] = $relatedproduct->contentid;
        $nav_listings_ids[$i]["link"] = "index.php?option=com_content&view=article&catid=10:products&id=".$listingid.":".$alias."&Itemid=16";
        $nav_listings_ids[$i]["title"] = $relatedproduct->title;
        $i++;
    }
}

// Save session
$nav_session->set('related_results_listings', $nav_listings_ids);

在我的产品页面上,我循环遍历$ _SESSION ['related_results_listings']的值,以找到我正在查看的项目的位置:

$nav_session = JFactory::getSession();

$nav_listings = $nav_session->get("related_results_listings");

// Locate the current listing in the search results list and retrieve the previous and next items

$index = 0;
for( $i=0; $i<count($nav_listings); $i++ )
{
    if( $nav_listings[$i]["id"] == $listing['Listing']['listing_id'] )
    {
        $index = $i;
        break;
    }   
}

如果有人愿意帮助我,我会很乐意解释上述任何一个问题。提前谢谢,祝大家新年快乐!

0 个答案:

没有答案