Skip to content

Commit

Permalink
send scenario added
Browse files Browse the repository at this point in the history
  • Loading branch information
noumo committed May 17, 2015
1 parent 1c0cab6 commit c42ef03
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions modules/guestbook/GuestbookModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class GuestbookModule extends \yii\easyii\components\Module
'enableTitle' => false,
'enableEmail' => true,
'preModerate' => false,
'enableCaptcha' => true,
'enableCaptcha' => false,
'mailAdminOnNewPost' => true,
'subjectOnNewPost' => 'New message in the guestbook.',
'templateOnNewPost' => '@easyii/modules/guestbook/en/mail/new_post',
'templateOnNewPost' => '@easyii/modules/guestbook/mail/en/new_post',
'frontendGuestbookRoute' => '/guestbook',
'subjectNotifyUser' => 'Your post in the guestbook answered',
'templateNotifyUser' => '@easyii/modules/guestbook/en/mail/notify_user'
'templateNotifyUser' => '@easyii/modules/guestbook/mail/en/notify_user'
];

public static $installConfig = [
Expand Down
1 change: 1 addition & 0 deletions modules/guestbook/api/Guestbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function api_form($options = [])
public function api_save($data)
{
$model = new GuestbookModel($data);
$model->scenario = 'send';
if ($model->save()) {
return ['result' => 'success'];
} else {
Expand Down
1 change: 1 addition & 0 deletions modules/guestbook/controllers/SendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class SendController extends \yii\web\Controller
public function actionIndex()
{
$model = new GuestbookModel;
$model->scenario = 'send';
$request = Yii::$app->request;

if ($model->load($request->post())) {
Expand Down
2 changes: 1 addition & 1 deletion modules/guestbook/models/Guestbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function rules()
['email', 'email'],
['title', 'string', 'max' => 128],
['reCaptcha', ReCaptchaValidator::className(), 'when' => function($model){
return $model->isNewRecord && Yii::$app->getModule('admin')->activeModules['guestbook']->settings['enableCaptcha'];
return $model->scenario == 'send' && Yii::$app->getModule('admin')->activeModules['guestbook']->settings['enableCaptcha'];
}],
];
}
Expand Down

0 comments on commit c42ef03

Please sign in to comment.