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 questions.
Of course, why the output is incorrect?
There is another (simple?) way to print the output into a Json code and do that?