【问题标题】:How to get intro image path of an article from db in Joomla如何从 Joomla 中的 db 获取文章的介绍图像路径
【发布时间】:2013-08-24 18:58:07
【问题描述】:

我正在开发一个新模块,它将在滑块上显示特色项目。

我已成功获取模块中的数据,但介绍图像存在问题。

我的查询在这里:

// Get a db connection.
$db = JFactory::getDbo();

// Create a new query object.
$query = $db->getQuery(true);

$query
        ->select(array('f.content_id', 'c.id', 'c.title', 'c.alias', 'c.images'))
        ->from('#__content AS c')
        ->join('INNER', '#__content_frontpage AS f ON (c.id = f.content_id)')
        ->where("c.language = '" . JFactory::getLanguage()->getTag() . "' AND c.state=1")
        ->order('f.ordering ASC');

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects.
$results = $db->loadObjectList();

foreach ($results as $r)
{
  $imagePath = $r->images;
  //.
  //.
  //.
}

如您所知,图像路径保存在目录表中的images 列中,如下所示:

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

我想知道如何从这些数据中提取介绍图像路径。是否有一个通用的函数/方法或者我应该使用 PHP 的 explode() 函数?

【问题讨论】:

    标签: php mysql joomla joomla3.1


    【解决方案1】:

    终于有人为此提出了一个很好的解决方案。

    PHP有一个不错的功能,json_decode()

    它将那个字符串(我后来知道它是 JSON)转换成一个键值数组。所以所有数据都可以访问:

    $pictures = json_decode('{"image_intro":"images\/products\/201191420496.jpg",
                              "float_intro":"",
                              "image_intro_alt":"",
                              "image_intro_caption":"",
                              "image_fulltext":"",
                              "float_fulltext":"",
                              "image_fulltext_alt":"",
                              "image_fulltext_caption":""
                             }',
                             true);
    
    echo $pictures['image_intro']; //gives images/products/201191420496.jpg
    

    【讨论】:

      猜你喜欢
      • 2014-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-27
      • 2017-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多