Giter Site home page Giter Site logo

Comments (9)

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

Hi,
Do you want send the email after comment has been created ?

from yii2-comments.

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

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.

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

Resolved by commit 1cbc050

from yii2-comments.

Gawran avatar Gawran commented on June 6, 2024

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:

Closed #30 #30.


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.

Gawran avatar Gawran commented on June 6, 2024

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;
      }
      }

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:

Closed #30 #30.


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.

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

Do you mean that you want get entity object in afterCreate event ?

from yii2-comments.

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

I think we can pass comment model to event, what do you think?

from yii2-comments.

ihorchepurnyi avatar ihorchepurnyi commented on June 6, 2024

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.

Gawran avatar Gawran commented on June 6, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.