[EXTENSION]: private-messaging This Yii Framework module allows you to add quickly private messaging
#2
Posted 04 July 2012 - 05:26 AM
I'm fairly new to Yii but have years of PHP experience so I'm not finding it too tricky to run with it and implement some of the addons people have created.
I am however confused on how to implement the private-messaging module, which is a shame as it looks really cool from what I've read/seen.
Do you have any additional information not available here on Github.
Ideally a more step-by-step process on adding it to an existing Yii Project or even an example project running this module.
Thanks in advance for your time.
Cade
Weavora Team, on 24 November 2011 - 05:44 AM, said:
#3
Posted 04 July 2012 - 05:46 AM
Cade, on 04 July 2012 - 05:26 AM, said:
I'm fairly new to Yii but have years of PHP experience so I'm not finding it too tricky to run with it and implement some of the addons people have created.
I am however confused on how to implement the private-messaging module, which is a shame as it looks really cool from what I've read/seen.
Do you have any additional information not available here on Github.
Ideally a more step-by-step process on adding it to an existing Yii Project or even an example project running this module.
Thanks in advance for your time.
Cade
I use this extension by following the instructions on the extension page, so they re complete and on step by step basis. But could you perhaps tell us where things goes wrong? any errors?any part you dont understand what It means?
#4
Posted 04 July 2012 - 07:45 AM
Sampa, on 04 July 2012 - 05:46 AM, said:
Hi Sampa,
I loaded all of the files into my project/protected directory however I wasn't sure where the file "MessageModule.php" was meant to be loaded.
When trying to open one of the Controllers, say Inbox I got the following error:
Trying to get property of non-object $this->userModel = Yii::app()->getModule('message')->userModel;
This appears to relate to the calling of the MessageModule.php file and specifically userModel variable, which appears to get assigned during the construct of the class and I assume I need to use something like the following mentioned in the Extension:
return array( 'modules' => array( 'message' => array( 'userModel' => 'User', 'getNameMethod' => 'getFullName', 'getSuggestMethod' => 'getSuggest', ), ), );
My problem is I'm not sure where to store MessageModule.php or how to load it. I thought maybe it needs to be put into the /config/main.php, but I'm really not sure.
I would really appreciate any information you can give me on this and any corrections to any of my observations I have mentioned above.
#5
Posted 04 July 2012 - 11:45 AM
There you also put the view/controller/models/data folders.
'modules'=>array(
....
'message' => array(
'userModel' => 'User', //make sure this is the same as the user model you use
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
....
),
#6
Posted 05 July 2012 - 05:31 AM
Sampa, on 04 July 2012 - 11:45 AM, said:
There you also put the view/controller/models/data folders.
'modules'=>array(
....
'message' => array(
'userModel' => 'User', //make sure this is the same as the user model you use
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
....
),
Yep, that did the trick.
Thanks for all your help
Just to recap for anyone else who is very new to Yii and wants to use this.
Step 1
Extract the contents of the ZIP to /protected/modules/message/
NOTE: the MessageModule.php file should be directly under this directory
Step 2
Modify the protected/config/main.php file and add the following in 'modules' (same location as 'gii'=>array):
'message' => array( 'userModel' => 'User', 'getNameMethod' => 'getFullName', 'getSuggestMethod' => 'getSuggest', 'viewPath' => '/message/fancy', ),
NOTE: The viewPath line at the end is optional and uses the fancy style rather than default
Step 3
Create the database as per the /protected/modules/message/data/message.sql
Step 4
Update your User module (or what module you specify in step 2 to include a getFullName and getSuggest module
examples for this are in the Private Messaging Extension
Step 5
Access the module via: ..../index.php/message
The above will depend on your URL structure
Issues
I did get 1 issue at step 5 where it complained it couldn't find the database {{messages}}.
I had to edit the protected/modules/message/models/Message.php and change the line:
return '{{messages}}';
To
return 'messages';
#7
Posted 05 July 2012 - 04:48 PM
Cade, on 05 July 2012 - 05:31 AM, said:
Thanks for all your help
Just to recap for anyone else who is very new to Yii and wants to use this.
.........
wow, I'm glad it solved it for you and amazing you wrote that "How-to". Thats the spirit.
I think you can have helped some beginners.
#8
Posted 25 July 2012 - 04:17 PM
Extract the contents of the ZIP to /protected/modules/message/
NOTE: the MessageModule.php file should be directly under this directory
Step 2
Modify the protected/config/main.php file and add the following in 'modules' (same location as 'gii'=>array):
'message' => array( 'userModel' => 'User', 'getNameMethod' => 'getFullName', 'getSuggestMethod' => 'getSuggest', 'viewPath' => '/message/fancy', ),
...
It is real step-by-step explanation.Thank you Cade.
#9
Posted 28 February 2013 - 02:33 PM
thanks for this extension. worked out of box

can you suggest how to customize name-suggestions feature to show names near the text-field rather than at the top corner of the page ?
thanks again.
#10
Posted 20 June 2013 - 03:25 AM
SuggestController.php Controller
<?php class SuggestController extends Controller { /** * @return array action filters */ public function filters() { return CMap::mergeArray(parent::filters(),array( 'accessControl', // perform access control for CRUD operations )); } /** * Specifies the access control rules. * This method is used by the 'accessControl' filter. * @return array access control rules */ public function accessRules() { return array( array('allow', // allow all users to perform 'index' and 'view' actions 'actions'=>array('user'), 'users'=>array('@'), ), array('deny', // deny all users 'users'=>array('*'), ), ); } public function actionUser() { $res =array(); if (isset($_GET['term'])) { $q = Yii::app()->request->getParam('term'); $userModels = (array) call_user_func(array( CActiveRecord::model(Yii::app()->getModule('message')->userModel), Yii::app()->getModule('message')->getSuggestMethod ), $q); if ($userModels) { foreach ($userModels as $userModel) { $fullName=call_user_func(array( $userModel, $this->getModule()->getNameMethod )); $users[] = array( 'label' => $fullName, 'value' => $fullName, 'id' => $userModel->getPrimaryKey(), ); } } } header('Cache-Control: no-store'); header('Pragma: no-store'); header("Content-type: application/json"); echo CJSON::encode($users); Yii::app()->end(); } }
Compose.php View
<?php $this->pageTitle=Yii::app()->name . ' - '.RE_t("Compose PMessages"); ?> <?php $this->breadcrumbs=array( RE_t('Messages')=>array('#'), RE_t("Compose"), ); ?> <?php $this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_navigation'); ?> <h2><?php echo RE_t('Compose New PMessages'); ?></h2> <div class="form"> <?php $form = $this->beginWidget('CActiveForm', array( 'id'=>'message-form', 'enableAjaxValidation'=>false, )); ?> <p class="note"><?php echo RE_t('Fields with <span class="required">*</span> are required.'); ?></p> <?php echo $form->errorSummary($model); ?> <div class="row"> <?php echo $form->labelEx($model,'receiver_id'); ?> <?php $this->widget('zii.widgets.jui.CJuiAutoComplete', array( 'name'=>'receiver', 'model'=>$model, 'value'=>"$receiverName", 'source'=>$this->createUrl('suggest/user'), // additional javascript options for the autocomplete plugin 'options'=>array( 'showAnim'=>'fold', 'select'=>"js: function(event, ui) { console.log(ui.item); $('#PMessages_receiver_id').val(ui.item['id']); }" ), )); ?> <?php echo $form->hiddenField($model,'receiver_id'); ?> <?php echo $form->error($model,'receiver_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'subject'); ?> <?php echo $form->textField($model,'subject'); ?> <?php echo $form->error($model,'subject'); ?> </div> <div class="row"> <?php echo $form->labelEx($model,'body'); ?> <?php echo $form->textArea($model,'body',array('style'=>'width: 400px; height: 100px;','maxlength' => 500)); ?> <?php echo $form->error($model,'body'); ?> </div> <div class="buttons"> <?php echo CHtml::submitButton(RE_t("Send"),array('class'=>'btn btn-primary')); ?> </div> <?php $this->endWidget(); ?> </div> <?php //TODO we are not using this jquery functions because Yii provides a better widget for autocompletion //and it is part of the standard FrameWork: zii.widgets.jui.CJuiAutoComplete //$this->renderPartial(Yii::app()->getModule('message')->viewPath . '/_suggest');
I hope this helps!
#11
Posted 13 July 2013 - 11:58 PM
"Active record "Message" has an invalid configuration for relation "receiver". It must specify the relation type, the related active record class and the foreign key."
My config/main.php:
'message' => array( 'userModel' => 'User', 'getNameMethod' => 'getFullName', 'getSuggestMethod' => 'getSuggest', //'viewPath' => '/message/fancy', 'receiverRelation' => array( CActiveRecord::BELONGS_TO, 'User', 'on' => 'User.id = receiver_id' ), ) 'senderRelation' => array( CActiveRecord::BELONGS_TO, 'User', 'on' => 'User.id = sender_id' ), ),
Please help me !!!!
#12
Posted 14 July 2013 - 05:44 AM
https://www.dropbox....6mo/message.rar
https://www.dropbox....6mo/message.rar
#13
Posted 03 September 2013 - 01:21 PM
If anyone has done it, Could you explain how-to?
PD. i have integrated everything with CRUGE but it seems that doesnt work:
- For example, doesnt find any user in suggest
- I have inserted a message directly in table via phpmyadmin and then in menu it shows correctly that there's a new message but when i go to inbox i get an error (it seems that try to get the sender username) :
Missing argument 2 for CrugeUser::__construct(), called in C:\wamp\www\yii\framework\db\ar\CActiveRecord.php on line 395 and defined
public function __construct($username, $password, $authmode = 'default') 68 { 69 $this->username = $username; 70 $this->password = $password; 71 $this->authmode = $authmode; 72 $this->storeduser = null; 73 74 Yii::log(__METHOD__ . "\n", "info"); 75 }
#14
Posted 20 November 2013 - 11:55 PM