What is the archetecture of private message feature in this Yii Forum

I read the tutorials several time, but found out there a lot of features on Internet that I couldn’t even figure out what it is. For example the Private Message function of this Yii forum. (picture in the attachment)

by using firebug, I can see it is called through:

What’s in this action to produce a modal dialog on current page? How does this work together ajax, or jquery?

Can you give me some ideas on how to implement this feature?

Thank you very much!

You mean something like that?




<?php

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

              'id' => 'mydialog',

              'options' => array(

                  'title' => 'Title Dialog',

                  'autoOpen' => false,

                  'modal' => true,

              ),

          ));

          $this->renderPartial('/site/pages/template');

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

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

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

          ));

?>



Thanks for your help! Your code can generate a dialog which I already know.

<a title="PM this member" href="http://www.yiiframework.com/forum/index.php?app=members&module=messaging&section=send&do=form&fromMemberID=6712">…</a>

If you take a look at this function using Firebug, it’s called by a link(a module/controller/action with severa parameters). There is no onClick event to trigger the dialog.

How does this work?

[color=#1C2837][size=2]<a title="PM this member" href="http://www.yiiframework.com/forum/index.php?app=members&module=messaging&section=send&do=form&fromMemberID=6712">…</a>

[/size][/color]

[color=#1C2837][size=2]

[/size][/color]

[color=#1C2837][size=2][color=#000000][size=3]My question is the parameter is already coded in the URL to call an action. why this action can generate a dialog? [/size][/color][/size][/color]

[color=#1C2837][size=2][color=#000000][size=3]How does the dialog interact with the action?[/size][/color][/size][/color]

[color=#1C2837][size=2][color=#000000][size=3]

[/size][/color][/size][/color]

[color=#1C2837][size=2][color=#000000][size=3]Thanks![/size][/color][/size][/color]

Hi nettrinity,

First of all, I am pretty sure that the private messaging is not a feature implemented by Yii on this site, but by the forum software (IP.Board). Therefore, the model-view-controller may be implemented differently on not at all in that software. I’m not familiar with its source.

Secondly, and I haven’t really sifted through it much, I am guessing that one of the external JavaScript files of IP.Board (<somefile>.js) attached the onclick event to the PM button you see. This is possible without actually having to write the onclick call in the HTML. My soon to be launched site (yay! :D) uses similar techniques, as it helps to keep the HTML clean. Yii has jQuery in its core distribution, which actually makes attaching events (click, load, and so on) pretty easy.

I feel the same. Even if it use external js file, how does the dialog knows the message is from whom to whom?

I am looking forward to your site!

Well, here is part of the html that shows the link to send you a PM:


<li class='pm_button' id='pm_121623_18290'><a href='http://www.yiiframework.com/forum/index.php?app=members&amp;module=messaging&amp;section=send&amp;do=form&amp;fromMemberID=18290' title='PM this member'>...

It basically boils down to the following steps (or approximation of them):

[list=1]

[*]The PHP page includes the JavaScript file

[*]The JS file is executed once the body is loaded

[*]It finds each li tag that has the class pm_button

[*]it attaches a click event handler that renders the JavaScript PM form

[*]it prevents the actual page from opening (as the JS form already handles the message

[/list]

It is not difficult to get the url from the a href in JavaScript. And if you have the url, you can use a number of techniques to find the receiver’s user id, which is rather unfortunately named fromMemberID. It would probably be better had it been named toMemberID. It might also use the pm_121623_18290 id from the li tag to figure out the PM has to be send to you.