<div> <div class="spoiler-title closed"> <?php echo "Розгорнути відгук про навчання &#9660" ?></div> <div class="spoiler-body"> <img src="<?php echo StaticFilesHelper::createPath('image', 'graduates', "recall.png"); ?>"> <?php echo $data['recall'] ?> </div> </div> 

I use this script:

 $(document).ready(function() { $('.spoiler-body').hide(); $('.spoiler-title').click(function(){ $(this).toggleClass('opened').toggleClass('closed').next().slideToggle(); if($(this).hasClass('opened')) { $(this).html('Згорнути відгук про навчання \u25B2'); } else { $(this).html('Розгорнути відгук про навчання \u25BC'); } }); }); 

The name of the spoiler should be taken from the database <?php echo Yii::t('блабла', '№стр.') ?> .

Update

When you click on the <?php echo "Розгорнути відгук про навчання ▼" ?></div> in js $(this).html('Згорнути відгук про навчання \u25B2'); and $(this).html('Розгорнути відгук про навчання \u25BC');

  • can explain the situation. did not fully understand the question. Do you want the title body fill in from the database? - Saidolim
  • how to transfer the value from the * .php file to the * .js file - todorovskiy

1 answer 1

need to do 2 things

  1. on the php side, create a controller and function to handle some kind of link. Inside the function do actions

     echo Yii::t('блабла', '123') 
  2. Now on the js side of the file

     $(document).ready(function () { $(".spoiler-title").on('click', function () { requestHtml = $.ajax({ url: 'ссылка на контроллнр/функция/' + 'строка с параметрами', type: "GET", dataType: "html" }); requestHtml.done(function (respose, status, xhr) { // тут можно и проверки ставить как вам нужно. // А так если проверки большые делайте в php стороне $('div.spoiler-body').html(response); }); }); }); 

you can also use dataType: "json" instead of dataType: "html" and process as needed

I think it will help

  • Thanks, I will try. - todorovskiy