2014-05-14 3 views
0

기사 구성 요소 외부의 기사에 대한 이미지 소개를 검색하려고합니다. 어떻게 내가 만 검색 할 수 있습니다joomla 데이터베이스에서 단일 매개 변수 가져 오기

{"image_intro":"images\/myimage.jpg","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"images\/myimage.jpg","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""} 

: 나는이 쿼리를 사용하고 있습니다 :

$db = JFactory::getDBO(); 
$query = $db->getQuery(true); 
$query->select('images') 
->from('#__content') 
->where('id = 151'); 
$db->setQuery($query); 
$image = $db->loadResult(); 
echo $image; 

문제는 많은 매개 변수를 저장하는 데이터베이스 필드,이다, 내 쿼리의 결과가 이것이다 "image_intro"매개 변수?

답변

2

먼저 데이터베이스 쿼리에서 탈출하는 것을 잊지 마십시오. 나는 당신을 위해 일부 변경했습니다 :

images/image_name.jpg 
:

$db = JFactory::getDbo(); 
$query = $db->getQuery(true); 
$query->select($db->quoteName('images')) 
     ->from($db->quoteName('#__content')) 
     ->where($db->quoteName('id') . ' = '. $db->quote('151')); 
$db->setQuery($query); 
$image = $db->loadResult(); 

당신은 다음 echo $path를 사용하는 경우 다음과 같은 출력을 얻을 것이다 그래서

$image_intro = json_decode($image); 
$path = $image_intro->image_intro; 

같은 결과를 json_decode 필요

다음과 같이 이미지를 표시 할 수 있습니다.

<img src="<?php echo JUri::root() . $path; ?>" /> 
1

나는 단순히 ContentModelArticle을 얻은 다음 특정 기사 ID를로드합니다.

/* Lets say the article ID = 151 */ 
$id = 151; 

/* Get an instance of the generic articles model 
    @var ContentModelArticle $model */ 
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true)); 
$myArticle = $model->getItem($id); 

/* That way you have access to all the use params as well as the image you're after */ 
$images = json_decode($myArticle->images); 
$image_intro = $images->image_intro; 

기사의 URL은 ...

$urls = json_decode($myArticle->urls); 

또는 제 PARAMS ...

$params = $myArticle->params; 
$page_heading = $params->get('page_heading'); 

다른 유용한 PARAMS을 ... 같은 방법으로 처리 할 수 ​​

$params->get('show_publish_date'); 
$params->get('show_create_date'); 
$params->get('show_hits'); 
$params->get('show_category'); 
$params->get('show_parent_category'); 
$params->get('show_author'); 
관련 문제