1

The item of my interest is in the __zoo_item table. My query:

$query
    ->select($db->quoteName(array('params')))
    ->from($db->quoteName('#__zoo_item'));

$db->setQuery($query);
$resultado = $db->loadObjectList();

The contents of params is a JSON like this:

 {
    "metadata.title": "",
    "metadata.description": "",
    "metadata.keywords": "",
    "metadata.robots": "",
    "metadata.author": "",
    "config.enable_comments": "0",
    "config.primary_category": "27"
}

I need to retrieve the value of primary_category. That is, I need retrieve: 27. How do I do that? I try to recover it as follows:

foreach ($resultado as value) {
    if ( is_object($value) ) {
        echo $value->config.primary_category;
    }
}

This is the best way to do this? The browser returns this: primary_category. How to retrieve the value: 27?

0

ZOO syntax is a bit different. Check this out: http://yootheme.com/zoo/documentation/developers/accessing-element-data

0

I don't think your code is the canonical way to access ZOO parameter values, but using your method you probably want something like:

$value = json_decode($value);
$primary_category = $value->{'config.primary_category'});
0

The dot in property name is causing the issue. Multiple ways to solve it:

  1. Assign property name to a variable:

    $value = json_decode($value);

    $property = 'config.primary_category';

    echo $value->$property;

  2. Enclose property value in curly brackets:

    $value = json_decode($value);

    echo $value->{'config.primary_category'};

  3. Turn params into Registry object (this is the Joomla way):

    use Joomla\Registry\Registry;

    $value = new Registry($value);

    echo $value->get('config.primary_category');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.