Messages
This Yii Framework module allows you to add quickly private messaging into your application.
GitHub - https://github.com/weavora/yii-messages
Features included:
This module was tested with 1.1.8 but should work with any version.
MessageModule requires a couple of methods to be defined in your User model (see below):
If you want to use modules' default layout make sure that it is defined via double slash ("//"). Usually default layout is defined in basic controller class.
// class Controller public $layout='//layouts/column1';
Create necessary tables using SQL file - data/message.sql
There are config settings of modules section below:
return array(
'modules' => array(
'message' => array(
'userModel' => 'User',
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
),
);
In order to use module you should specify User model that is used in the application MessageModule::userModel.
If necessary, specify relations for Sender and Receiver MessageModule::senderRelation and MessageModule::receiverRelation.
'receiverRelation' => array(
CActiveRecord::BELONGS_TO,
'MyUserModel',
'',
'on' => 'MyUserModel.my_custom_id = receiver_id'
)
If you do not use Yii assets build-in functionality you will need to connect jQuery and jQuery UI(with styles) libraries. You can find them in modules folder.
Insert items into zii.widgets.CMenu array (protected/views/layouts/main.php)
array(
'url' => Yii::app()->getModule('message')->inboxUrl,
'label' => 'Messages' .
(Yii::app()->getModule('message')->getCountUnreadedMessages(Yii::app()->user->getId()) ?
' (' . Yii::app()->getModule('message')->getCountUnreadedMessages(Yii::app()->user->getId()) . ')' : ''),
'visible' => !Yii::app()->user->isGuest),
// config
return array(
'modules' => array(
'message' => array(
'userModel' => 'User',
'getNameMethod' => 'getFullName',
'getSuggestMethod' => 'getSuggest',
),
),
);
// class User
public function getFullName() {
return $this->username;
}
public function getSuggest($q) {
$c = new CDbCriteria();
$c->addSearchCondition('username', $q, true, 'OR');
$c->addSearchCondition('email', $q, true, 'OR');
return $this->findAll($c);
}
If you are not satisfied with the standard views you can easily replace them with your own just linking path to their folder through MessageModule::viewPath.
//config
return array(
'modules' => array(
'message' => array(
...
// for app/protected/views/messagesModuleCustom
'viewPath' => '//messagesModuleCustom',
),
),
);
// app/protected/views/messagesModuleCustom directory listing
..
compose.php
inbox.php
sent.php
view.php
It is possible to determine each recipient by URL (for example, under user profile page). To do this, you should add his id at the end of URL.
http://example.com/message/compose/1
In this case recipients' name will be automatically inserted in the form.
Total 14 comments
Autocomplete issue update: message/controllers/SuggestController.php
Line6: $q = Yii::app()->request->getParam('name_startsWith');
When I change to $q = Yii::app()->request->getParam('');
I get a popup list in the top left corner of my browser (firefox and chromium) with the username fields from my database. (not filtered by receiver text) but when i select a value it inputs the corresponding receiver_id value and the form submits properly.
First of all, I would like to say that this is a great extension that is going to save me many hours :) I appreciate the contribution. Hoping for a little help here.
I am using the Yii User module (yii-user)
Everything is working, and the direct URL eg: ...
message/compose/1which prepopulates the receiver wtih valueadminfrom user.username. I am able to send a message this way.However, when typing in the receiver name 'admin' and sending, I get validation error: receiver name must be specified.
Also, while typing in the receiver field, the spining icon spins but does not lookup and find the value. Can you help. I am wondering if i need to configure the relations? But Everything else seems to work so I'm stuck.
Can someone help us out? Thanks!
hi!
very nice extension, my only problem is, that autosuggest is not working. firebug says the data is found, in json it's there, but it doesn't show up, the small loading icon keeps turning around. I'm also using bootstrap, can it be the problem? is there a workaround for this?
thanks a lot! c
hi!
very nice extension, my only problem is, that autosuggest is not working. firebug says the data is found, in json it's there, but it doesn't show up, the small loading icon keeps turning around. I'm also using bootstrap, can it be the problem? is there a workaround for this?
thanks a lot! c
Hi everybody.
I couldn't send direct message through "/message/compose/1" method. Is there any other way to send direct message ?
Please specify the configuration and examples in details..?
I have a bug with Receiver username then i try to send a message i wrote into Receiver field that user i whant to send message bu i got error, Receiver cannot be blank.
There is bug?
hi,
I like the private messaging extension, it's been done in a standard way.... but I wish if you could improve it to be AJAX-based and facebook alike :)
take care!
Cool extension, thanks
Each time I send the message to myself. I will be not able to open the sent page then. It appears:
CDbCommand failed to execute the SQL statement: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Users.id' in 'where clause'. The SQL statement executed was: SELECT
receiver.idASt1_c0,receiver.usernameASt1_c1,receiver.passwordASt1_c2,receiver.emailASt1_c3,receiver.activkeyASt1_c4,receiver.createtimeASt1_c5,receiver.lastvisitASt1_c6,receiver.superuserASt1_c7,receiver.statusASt1_c8,receiver.fb_uidASt1_c9FROMtbl_usersreceiverWHERE (Users.id = receiver_id)Any ideas?
I must say, now when I have gone thrue it some more, this is just pure quality.
Simple,yet effective and yes, just nice.
Keep doing extentions,weovora!:)
Here Is how I did the layout: http://dc104.2shared.com/download/1NophlQX/message-compose.png?tsid=20120319-201651-1025a150
Sharing just to give inspiration
This one is cool, It worked flawless right away, adding a table prefix was no problem either.
The fancy bootstrap view files was a huge win! BUT together with the Yii-Bootstrap extention some of my bootstraped contents (that I had before adding this module) got bugged. So currently I'm testing without the bootstrap css file included in the fancy view folder.
And well, all looks okey:) So, thank you very much for this. If I notice something more I will add another comment.
Hi perochak, Thanks for feedback. Did you find it useful for your project? Any ideas on how to improve it?
Regards, Mike
Thanks - Nice work
Leave a comment
Please login to leave your comment.