Yii Framework Forum: Sending mail when record inserted - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Sending mail when record inserted Rate Topic: -----

#1 User is offline   Ted 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 25-July 10

Posted 25 July 2010 - 11:18 AM

Hey im new to the Yii so sorry if any of questions sound stupid. I created a model called User using the CRUD setup. Basically allows users to register. I was wondering if anyone could tell me how to have that the once the user creates their account, an email is then sent to the administrator (myself) saying a new user has registered.

I would imagine it would go into this function in the controller?

	public function actionCreate()
	{	 
		$model=new User;
		
		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['User']))
		{
			$model->attributes=$_POST['User'];
			if($model->save())
				$this->redirect(array('view','id'=>$model->userId));
		}
		
		
		$this->render('create',array('model'=>$model,'isAdmin'=>!Yii::app()->user->isGuest));
	}

0

#2 User is offline   mbi 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 603
  • Joined: 08-May 09

Posted 25 July 2010 - 11:42 AM

if you want to send a mail after saving a user, you can do it in the User's afterSave-Method
0

#3 User is offline   jonah 

  • Advanced Member
  • Yii
  • Group: Yii Dev Team
  • Posts: 733
  • Joined: 27-November 08
  • Location:California (US)

Posted 25 July 2010 - 11:44 AM

[...]
if($model->save) { //line 11 in your code
   $model->sendEmail(); //todo
   $this->redirect(array('view','id'=>$model->userId));
}
[...]


afterSave works too
http://php-thoughts.cubedwater.com - my bloggings about Yii
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users