modal yes/no window

Hello, this is my first post here :)

Is there an easy way to show a simple modal confirmation window (typical yes/no modal window) from within the authenticate() method in UserIdentity.php?

My problem is that when a user is in the login process of my app, I’d need to include some logic, and depending on a simple question, the login process has to invoke some different actions and render some forms accordingly.

thank you very much in advance,

I’ve been browsing forums and docs for many hours trying to find out a solution without any success

:(

Welcome to the forum! :]

The best solution I would propose you, would be to use jQuery UI Dialog Box, which you can easily integrate into any Yii (or PHP) application (it is very easy to use JavaScript library) and provides you with everything you need - i.e. popping up dialog box, handling Yes and No buttons and stuff like that.

Thank you very much for the hint and the welcome :) however, I can’t figure out how to invoke the modal window from within my code




UserIdentity.php


class UserIdentity extends CUserIdentity

{

	 

	 private $_id;

	 public function authenticate()

	 {


          // some code here blah blah blah...


         // I want the modal window to be called here




	  }

}



I created a dialog.php in views/site with a test sample dialog , like this




	 $this->beginWidget('zii.widgets.jui.CJuiDialog', array(

        'id'=>'mydialog2',

        'options'=>array(

            'title'=>'Add New Item',

            'autoOpen'=>false,

            'modal'=>true,

            'buttons'=>array(

                'Add Item'=>'js:addItem',

                'Cancel'=>'js:function(){ $(this).dialog("close");}',

            ),

        ),

    ));


    echo '<div class="dialog_input"><input type="text" id="item-name-input" name="item-name"/></div>';


    $this->endWidget('zii.widgets.jui.CJuiDialog');


    echo CHtml::link('open dialog', '#', array(

            'onclick'=>'$("#mydialog2").dialog("open"); return false;',

    ));

?>

<?php /* include your relevant javascript somewhere */ ?>

<script type="text/javascript" >

    function addItem(){

        $(this).dialog("close");

        alert( $("#item-name-input").val() + " has been added");

    }

</script>



so, the thing is, how could I invoke or render this view from within the authenticate() method

I’ve just managed to sort it out :D

Still some minor details to be fixed, specially the rendering (the modal window flashes for a moment while the page is loading in the browser (chrome). I’ll try with different browsers…

Anyway, it works nicely :)

I’ll post here the link with detailed instructions just in case it could be useful to other people

flash messages

This is kind of hardest part, as jQuery displaying dialogs is client-side language run, when whole page code is done transmitting to browser, while PHP code is run on server before actual sending begins.

I always had problems in co-operation of jQuery/JavaScript and PHP/Yii, therefore I’m glad you’ve found solution to your problems yourself.