CMS Joomla Mastering Development

Controller Joomla – Output Class construct for color css style

thanks to you i’m learning a lot about php and Joomla Develop! Many thanks!

Now i’m trying to understand php class into joomla and construct output

i’ve created this class into my controller.php

class ColorStyle {
public $OpenJs = "<script>";
public $GetElementRisultato = "document.getElementById('risultato')";
public $StyleColor = '.style.color =';
public $CloseJs = "</script>";
//public $StyleColor;
//public $name;
public $color;

function __construct($color) {

    $this->value = $color;

function get_color() {
    return $OpenJs.$GetElementRisultato.$this->value.$closeJs;



Calling the class like

$cambia_colore = new ColorStyle($color = '"red "');

  echo $cambia_colore->get_color();

The output is “red” instead of <script>document.getElementById('risultato').style.color = "red" </script>

The output will be used for change style color after an Ajax Call.
I have 2 question.

1) Of course, why the output is incorrect?

2) There is another (simple?) way to print the output into a Json code and do that?

Many thanks again.


Leave a Reply

Your email address will not be published. Required fields are marked *