Comments (9)
Hi,
Do you want send the email after comment has been created ?
from yii2-comments.
Please use the following code for afterCreate
event
'modules' => [
'comment' => [
'class' => 'yii2mod\comments\Module',
// use comment controller event example
'controllerMap' => [
'default' => [
'class' => 'yii2mod\comments\controllers\DefaultController',
'on afterCreate' => function ($event) {
// get userId
$event->getUser()->getId();
// get identity
$event->getUser()->getIdentity();
// your custom code
}
]
]
]
]
https://github.com/yii2mod/yii2-comments#configuration
from yii2-comments.
Resolved by commit 1cbc050
from yii2-comments.
Yes. I want to send an email every time the comment is created. Sorry for
the late response it's different time zone here.
Thanks for the solution.
On Sun, Nov 6, 2016 at 12:31 PM, Igor Chepurnoy [email protected]
wrote:
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#30 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEv4-0b_4g0FKXcd6IzenqryI_sEVLHIks5q7bqIgaJpZM4KqWH_
.
Sa poštovanjem,
Miodrag Gavranov
from yii2-comments.
May I suggest to pass and entity data or only entityId in $event object? I
need that connection so I can extract recipients for my MailEvent. Basicly
I'll trigger my own afterUpdate event in your afterCreate event.
something like:
public function actionCreate($entity)
{
/* @var $module Module /
$module = Yii::$app->getModule(Module::$name);
$event = Yii::createObject(['class' => CommentEvent::className(),
'user' => Yii::$app->user]);
$commentModelClass = $module->commentModelClass;
$decryptEntity =
Yii::$app->getSecurity()->decryptByKey(utf8_decode($entity),
$module::$name);
if ($decryptEntity !== false) {
$entityData = Json::decode($decryptEntity);
/ @var $model CommentModel */
$model = new $commentModelClass;
$model->setAttributes($entityData);
$event->entityData = $entityData;
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->trigger(self::EVENT_AFTER_CREATE, $event);
return ['status' => 'success'];
} else {
return [
'status' => 'error',
'errors' => ActiveForm::validate($model)
];
}
} else {
return [
'status' => 'error',
'message' => Yii::t('yii2mod.comments', 'Oops, something
went wrong. Please try again later.')
];
}
}
and add public property in CommentEvent named entityData or something
similar... or define getter and setter.
/**
-
Class CommentEvent
-
@Package yii2mod\comments\events
/
class CommentEvent extends Event
{
/*- @var User
*/
private $_user;
public $entityData;
/**
- @return User
*/
public function getUser()
{
return $this->_user;
}
/**
- @param User $user
*/
public function setUser(User $user)
{
$this->_user = $user;
}
}
- @var User
On Sun, Nov 6, 2016 at 5:03 PM, Miodrag Gavranov <[email protected]
wrote:
Yes. I want to send an email every time the comment is created. Sorry for
the late response it's different time zone here.
Thanks for the solution.On Sun, Nov 6, 2016 at 12:31 PM, Igor Chepurnoy [email protected]
wrote:—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#30 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AEv4-0b_4g0FKXcd6IzenqryI_sEVLHIks5q7bqIgaJpZM4KqWH_
.Sa poštovanjem,
Miodrag Gavranov
Sa poštovanjem,
Miodrag Gavranov
from yii2-comments.
Do you mean that you want get entity object in afterCreate
event ?
from yii2-comments.
I think we can pass comment model to event, what do you think?
from yii2-comments.
I was update the CommentEvent class, now you can get the saved comment object as following:
'on afterCreate' => function ($event) {
$event->getCommentModel();
// your custom code
}
from yii2-comments.
Even better! Thanks.
On Sun, Nov 6, 2016 at 7:48 PM, Igor Chepurnoy [email protected]
wrote:
I was update the CommentEvent class, now you can get the saved comment
model object as following:'on afterCreate' => function ($event) { $event->getCommentModel(); // your custom code}
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#30 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEv4-0WFqv5Z2UFncMawxZlrs8ZOQW77ks5q7iDugaJpZM4KqWH_
.
Sa poštovanjem,
Miodrag Gavranov
from yii2-comments.
Related Issues (20)
- При переопределении имени таблицы в своей модели не работает менеджмент
- Не работает с включенным чпу HOT 1
- Default comment status
- Initialization problem: No new migrations found. Your system is up-to-date. HOT 1
- Problem with the encoding of the createComment using CommentWidget
- Are you accepting PRs at the moment? HOT 1
- Fail migrate m161114_094902_add_url_column_to_comment_table
- 404 - Create Comment Not Found HOT 1
- How to know count of comments from relatedTo ?
- Collaboration with https://docs.infiniteajaxscroll.com/
- No Reason Phrase HOT 7
- How to update entity model using event afterCreate? HOT 1
- API availability.
- "Carbon 1 is deprecated" warning HOT 3
- When is the next release planned? HOT 3
- Do you take donate? HOT 2
- Add attachments and editor
- Readonly Comments Feature
- Reinitialize the javascript methods HOT 2
- Не накатываются миграции HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yii2-comments.