A
A
AlexSer2017-08-27 20:19:10
Yii
AlexSer, 2017-08-27 20:19:10

Yii2 how to fire action for modal window?

Hello everyone, I'm new to Yii2, a lot of things are not clear) so I can ask stupid questions .... Guys, tell me how to organize the launch of the action.
Let's say I have a main page with the main url www.test.ru/system - system the main page of the class, i.e. rendering takes place on actionIndex.
on system.php I have a panel with buttons, for example, let's take three buttons

<button id='zhurnal">Журнал<button>
<button id='status">Статус<button>
<button id='createZakupki">Закупка<button>

all three buttons open modal windows. So far, all data in modal windows comes from one actionIndex. But I want to unload Akshion.
The question is how to make it so that each button has its own action?
To launch actionZhurnal, it is necessary that there is a transition to system/zhurnal -> but then I lose the panel with three buttons .....
I don’t want to duplicate the panel code with js scripts ..... I think that I need to dig towards the URl manager.
I hope I explained it as best I could ... Tell me pliz ... Ideally, I want modal windows to be stored each in a separate file _modalZhurnal.php where there would be only a design in the output data, but now I have all modal windows registered in the system.php view
if there is an example, give a link) Thank you all!!! :D

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
link_irk, 2017-08-28
@link_irk

<button id="zhurnal" data-url="/system/journal">Журнал<button>
<button id="status" data-url="/system/status">Статус<button>
<button id="createZakupki" data-url="/system/order">Закупка<button>

$('button[data-url]').click(function(e) {
  $.ajax({
    url: $(this).data('url'),
    type: 'get',
    dataType: 'html'
  }).done(function(response) {
    $('.modal-body').html(response);
  });
})

// ...
public function actionJournal()
{
  return $this -> renderAjax('journal');
}
// ...

A
AlexSer, 2017-08-28
@AlexSer

Why don't js work through renderAjax?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question