데이터베이스의 k2_items 테이블에서 정보를 얻으려고 사용하는 코드가 있지만 extra_fields에 대한 정보는 JSON 문자열이며 사람이 읽을 수있는 ID/인쇄해야하는 값.Joomla K2에서 추가 필드를 표시하는 방법
여기는 데이터베이스 정보를 표시하는 데 사용하는 코드와 extra_fields 값을 가져 오는 코드를 시도했습니다.
<?php
define('_JEXEC', 1);
define('JPATH_BASE', realpath(dirname(__FILE__).''));
define('DS', DIRECTORY_SEPARATOR);
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php');
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
$user = JFactory::getUser();
$session =& JFactory::getSession();
$user = JFactory::getUser();
//echo 'Username is ' . $user->username;
if($user->username === NULL)
//user is not logged in
{
exit('You are not authorized to view this page. <a href = "' . JURI::root() . '">Please return to the homepage and login using the proper username/password.</a>' . $user->username);
}
else
//user is logged in
{
echo "<p>Welcome $user->username</p>";
echo '<p><a href = "http://ac.tradewindus.com/index.php?option=com_content&view=featured&Itemid=143">Go here to log out</a></p>';
$db=JFactory::getDBO();
$sql="SELECT * FROM #__k2_items WHERE published='1'";
$db->setQuery($sql);
$list=$db->loadObjectList();
foreach($list as $item)
{
echo "<pre>";
echo print_r($item, true);
echo "</pre>";
//convertArray to use ids as key
$extrafields = array();
foreach($item->extra_fields as $item)
{
$extrafields[$item->id] = $item->value;
}
echo $extrafields[1];
echo $extrafields[2];
echo $extrafields[3];
echo $extrafields[4];
echo $extrafields[5];
//echo "<p>Title: $item->title</p>";
//echo $item->introtext;
}
}
?>
그리고 이것은 각 "foreach"루프 출력에 대한 결과입니다.
stdClass Object
(
[id] => 83
[title] => SPEC SHEET: PANORAMAH 38 SASH BI-RAIL
[alias] => spec-sheet-panoramah-38-sash-birail
[catid] => 4
[published] => 1
[introtext] =>
SPEC SHEET: PANORAMAH 38 SASH BI-RAIL
[fulltext] =>
[video] =>
[gallery] =>
[extra_fields] => [{"id":"1","value":""},{"id":"2","value":["1"]},{"id":"3","value":["4"]},{"id":"4","value":["1","2"]},{"id":"5","value":["7"]},{"id":"6","value":["4"]}]
[extra_fields_search] => PanoramAH Minimal Frame Door Window Sliding Spec Sheets
[created] => 2014-01-09 00:00:00
[created_by] => 550
[created_by_alias] =>
[checked_out] => 0
[checked_out_time] => 0000-00-00 00:00:00
[modified] => 2014-08-06 22:44:57
[modified_by] => 550
[publish_up] => 2014-01-09 00:00:00
[publish_down] => 0000-00-00 00:00:00
[trash] => 0
[access] => 1
[ordering] => 14
[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] => *
)
엑스트라 필드가 맨 아래에 표시되어야하지만 아무 것도 반환되지 않습니다. extra_fields가 db 출력에 인쇄되면 값은 [1]과 같은 숫자입니다. 하지만 K2 백엔드를 보면 텍스트 응답 또는 드롭 다운 선택입니다. 인간이 읽을 수있는. 나는 Joomla 개발자가 아니기 때문에 어떤 종류의 JRegistry가 있는지 또는 사용해야만하는 것이 있는지 모르겠다. 그러나 나는 올바른 방향으로 향하게되어 있음을 감사하게 생각한다. : D
http://www.itoctopus.com/on-leveraging-the-power-of-k2s-extra-items 감사합니다 2 :. K2에 대한 추가 항목의
이 참조 또는 뭔가. 나는 if 문과 switch 함수로 문제를 해결했다. – Vales