1

I'm developing a Joomla 3.x.x module which connects through to a components table in the database.

I have got the following code in the helper.php which outputs the variables successfully:

public static function renderElement($table_name, $field_name, $field_value) {
    $result = '';

    switch ($table_name) {

    case '#__competition_data':
    switch($field_name){
    case 'id':
    $result = $field_value;
    break;
    case 'title':
    $result = $field_value;
    break;
    case 'introtext':
    $result = $field_value;
    break;
    case 'maintext':
    $result = $field_value;
    break;
    case 'image':
    $result = $field_value;
    break;
    case 'question':
    $result = $field_value;
    break;
    case 'correct_answer':
    $result = $field_value;
    break;
    case 'false_answer1':
    $result = $field_value;
    break;
    case 'false_answer2':
    $result = $field_value;
    break;
    case 'closing_date':
    $result = $field_value;
    break;
    case 'terms':
    $result = $field_value;
    break;
    case 'additional_info':
    $result = $field_value;
    break;
    case 'created_by':
    $user = JFactory::getUser($field_value);
    $result = $user->name;
    break;
    }
    return $result;
}

The frontend php file then outputs the above using the following:

<div class="span8"><?php echo ModCompetitionHelper::renderElement($params->get('item_table'), $field_name, $field_value); ?></div>

But they are outputted as different DIV's, one of them is an image so I want to be able to control what they are outputted as.

Ideally something along the lines of:

case '#__competition_data':
    switch($field_name){
    case 'id':
    $result = $field_value_id;
    break;

I can't work out how to do it though, any ideas please?

Thanks!

1 Answer 1

2
case 'image':
    $result = '<img src="' . $field_value . '" />';
    break;

How about this for example?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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