Get primarykey after save

I use ajax json. I need send primerykey after save().

How can do this if some people at a time will click on save it will work true?




<?php 


public function actionIndex()

{

	// ...

	$user = new User;

	$user->username = "johndoe";

	$user->password = "123";

	if ($user->save())

	{

		echo CJSON::encode($user->id);

	}

	//...

}