1
$this->registerJS(
'var ok = confirm("File already exists!! Do you want to overwrite file");
    if(ok)
    {
       "'.Url::toRoute('default/over-write?id=1').'";
    }
    else
    {
       "'.Url::toRoute('default/over-write?id=0').'";
    };',View::POS_READY);

The Url call is supposed to call actionOverWrite() in DefaultController. But this is not happening. How to call action from view?

Sujata
  • 951
  • 2
  • 10
  • 19

2 Answers2

4

You could simply try :

$this->registerJS('
    var ok = confirm("File already exists!! Do you want to overwrite file");
    window.location.replace("'.Url::toRoute('default/over-write').'" + "?id=" + (ok ? 1 : 0));
', View::POS_READY);

Read more about js redirection : How to redirect to another webpage in JavaScript/jQuery?

Community
  • 1
  • 1
soju
  • 25,111
  • 3
  • 68
  • 70
1

Or try this

$this->registerJS(
'var url = "'.Url::toRoute('default/over-write?id=').'";
    if(confirm("File already exists!! Do you want to overwrite file"))
    {
       window.location.href = url + '1';
    }
    else
    {
       window.location.href = url + '0';
    };',View::POS_READY);
arogachev
  • 33,150
  • 7
  • 114
  • 117
vitalik_74
  • 4,573
  • 2
  • 19
  • 27