访问K2项目的图像属性

时间:2014-03-29 13:15:36

标签: joomla joomla-k2

我正在开发一个模块,根据其类别ID显示特定数量的k2项目。我可以得到那些项目,但我无法访问它上面的图像。当我尝试$ item-> image时,会返回以下声明:

Notice: Undefined property: stdClass::$image

这是我从sql查询中获得的对象:


    stdClass Object
    (
        [id] => 5
        [title] => News test item
        [alias] => news-test-item
        [catid] => 4
        [published] => 1
        [introtext] => Some intro text
        [fulltext] => 
        [video] => 
        [gallery] => 
        [extra_fields] => []
        [extra_fields_search] => 
        [created] => 2014-03-28 21:42:01
        [created_by] => 252
        [created_by_alias] => 
        [checked_out] => 0
        [checked_out_time] => 0000-00-00 00:00:00
        [modified] => 0000-00-00 00:00:00
        [modified_by] => 0
        [publish_up] => 2014-03-28 21:42:01
        [publish_down] => 0000-00-00 00:00:00
        [trash] => 0
        [access] => 1
        [ordering] => 1
        [featured] => 0
        [featured_ordering] => 0
        [image_caption] => 
        [image_credits] => 
        [video_caption] => 
        [video_credits] => 
        [hits] => 0
        [params] => {"catItemTitle":"","catItemTitleLinked":"","catItemFeaturedNotice":"","catItemAuthor":"","catItemDateCreated":"","catItemRating":"","catItemImage":"","catItemIntroText":"","catItemExtraFields":"","catItemHits":"","catItemCategory":"","catItemTags":"","catItemAttachments":"","catItemAttachmentsCounter":"","catItemVideo":"","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"","catItemImageGallery":"","catItemDateModified":"","catItemReadMore":"","catItemCommentsAnchor":"","catItemK2Plugins":"","itemDateCreated":"","itemTitle":"","itemFeaturedNotice":"","itemAuthor":"","itemFontResizer":"","itemPrintButton":"","itemEmailButton":"","itemSocialButton":"","itemVideoAnchor":"","itemImageGalleryAnchor":"","itemCommentsAnchor":"","itemRating":"","itemImage":"","itemImgSize":"","itemImageMainCaption":"","itemImageMainCredits":"","itemIntroText":"","itemFullText":"","itemExtraFields":"","itemDateModified":"","itemHits":"","itemCategory":"","itemTags":"","itemAttachments":"","itemAttachmentsCounter":"","itemVideo":"","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"","itemVideoCaption":"","itemVideoCredits":"","itemImageGallery":"","itemNavigation":"","itemComments":"","itemTwitterButton":"","itemFacebookButton":"","itemGooglePlusOneButton":"","itemAuthorBlock":"","itemAuthorImage":"","itemAuthorDescription":"","itemAuthorURL":"","itemAuthorEmail":"","itemAuthorLatest":"","itemAuthorLatestLimit":"","itemRelated":"","itemRelatedLimit":"","itemRelatedTitle":"","itemRelatedCategory":"","itemRelatedImageSize":"","itemRelatedIntrotext":"","itemRelatedFulltext":"","itemRelatedAuthor":"","itemRelatedMedia":"","itemRelatedImageGallery":"","itemK2Plugins":""}
        [metadesc] => 
        [metadata] => robots=
    author=
        [metakey] => 
        [plugins] => 
        [language] => *
        [categoryname] => News-test
        [categoryid] => 4
        [categoryalias] => news-test
        [categoryparams] => {"inheritFrom":"0","theme":"","num_leading_items":"2","num_leading_columns":"1","leadingImgSize":"Large","num_primary_items":"4","num_primary_columns":"2","primaryImgSize":"Medium","num_secondary_items":"4","num_secondary_columns":"1","secondaryImgSize":"Small","num_links":"4","num_links_columns":"1","linksImgSize":"XSmall","catCatalogMode":"0","catFeaturedItems":"1","catOrdering":"","catPagination":"2","catPaginationResults":"1","catTitle":"1","catTitleItemCounter":"1","catDescription":"1","catImage":"1","catFeedLink":"1","catFeedIcon":"1","subCategories":"1","subCatColumns":"2","subCatOrdering":"","subCatTitle":"1","subCatTitleItemCounter":"1","subCatDescription":"1","subCatImage":"1","itemImageXS":"","itemImageS":"","itemImageM":"","itemImageL":"","itemImageXL":"","catItemTitle":"1","catItemTitleLinked":"1","catItemFeaturedNotice":"0","catItemAuthor":"1","catItemDateCreated":"1","catItemRating":"0","catItemImage":"1","catItemIntroText":"1","catItemIntroTextWordLimit":"","catItemExtraFields":"0","catItemHits":"0","catItemCategory":"1","catItemTags":"1","catItemAttachments":"0","catItemAttachmentsCounter":"0","catItemVideo":"0","catItemVideoWidth":"","catItemVideoHeight":"","catItemAudioWidth":"","catItemAudioHeight":"","catItemVideoAutoPlay":"0","catItemImageGallery":"0","catItemDateModified":"0","catItemReadMore":"1","catItemCommentsAnchor":"1","catItemK2Plugins":"1","itemDateCreated":"1","itemTitle":"1","itemFeaturedNotice":"1","itemAuthor":"1","itemFontResizer":"1","itemPrintButton":"1","itemEmailButton":"1","itemSocialButton":"1","itemVideoAnchor":"1","itemImageGalleryAnchor":"1","itemCommentsAnchor":"1","itemRating":"1","itemImage":"1","itemImgSize":"Large","itemImageMainCaption":"1","itemImageMainCredits":"1","itemIntroText":"1","itemFullText":"1","itemExtraFields":"1","itemDateModified":"1","itemHits":"1","itemCategory":"1","itemTags":"1","itemAttachments":"1","itemAttachmentsCounter":"1","itemVideo":"1","itemVideoWidth":"","itemVideoHeight":"","itemAudioWidth":"","itemAudioHeight":"","itemVideoAutoPlay":"0","itemVideoCaption":"1","itemVideoCredits":"1","itemImageGallery":"1","itemNavigation":"1","itemComments":"1","itemTwitterButton":"1","itemFacebookButton":"1","itemGooglePlusOneButton":"1","itemAuthorBlock":"1","itemAuthorImage":"1","itemAuthorDescription":"1","itemAuthorURL":"1","itemAuthorEmail":"0","itemAuthorLatest":"1","itemAuthorLatestLimit":"5","itemRelated":"1","itemRelatedLimit":"5","itemRelatedTitle":"1","itemRelatedCategory":"0","itemRelatedImageSize":"0","itemRelatedIntrotext":"0","itemRelatedFulltext":"0","itemRelatedAuthor":"0","itemRelatedMedia":"0","itemRelatedImageGallery":"0","itemK2Plugins":"1","catMetaDesc":"","catMetaKey":"","catMetaRobots":"","catMetaAuthor":""}
    )

我在这里缺少什么?

任何帮助将不胜感激。

编辑:我正在使用Joomla v2.5.18和K2 v2.6.8

2 个答案:

答案 0 :(得分:0)

你没有提到你正在使用的Joomla和K2版本。

Joomla> 1.6你应该解析" params"这样的财产:

$params = new JRegistry($item->params);

获取如下图像

J 1.6< => J 2.5.14

$params->getValue('itemImage')

J> = 2.5.14

$params->get('itemImage')

参考:http://api.joomla.org/cms-3/classes/JRegistry.html

答案 1 :(得分:0)

这就是K2 Content模块将图像添加到项目Object的方式(取自mod_k2_content / helper.php):

                //Images
            if ($params->get('itemImage'))
            {

                $date = JFactory::getDate($item->modified);
                $timestamp = '?t='.$date->toUnix();

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XS.jpg'))
                {
                    $item->imageXSmall = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XS.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageXSmall .= $timestamp;
                    }
                }

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_S.jpg'))
                {
                    $item->imageSmall = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_S.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageSmall .= $timestamp;
                    }
                }

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_M.jpg'))
                {
                    $item->imageMedium = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_M.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageMedium .= $timestamp;
                    }
                }

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_L.jpg'))
                {
                    $item->imageLarge = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_L.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageLarge .= $timestamp;
                    }
                }

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_XL.jpg'))
                {
                    $item->imageXLarge = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_XL.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageXLarge .= $timestamp;
                    }
                }

                if (JFile::exists(JPATH_SITE.DS.'media'.DS.'k2'.DS.'items'.DS.'cache'.DS.md5("Image".$item->id).'_Generic.jpg'))
                {
                    $item->imageGeneric = JURI::base(true).'/media/k2/items/cache/'.md5("Image".$item->id).'_Generic.jpg';
                    if ($componentParams->get('imageTimestamp'))
                    {
                        $item->imageGeneric .= $timestamp;
                    }
                }

                $image = 'image'.$params->get('itemImgSize', 'Small');
                if (isset($item->$image))
                    $item->image = $item->$image;

            }

您应该拥有所需的一切,否则请查看K2内容模块。