Yii Framework Forum: How To Register User From Another Controller - Yii Framework Forum

Jump to content

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

How To Register User From Another Controller Rate Topic: -----

#1 User is offline   razor101 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 12
  • Joined: 06-July 13

Posted 29 July 2013 - 07:48 AM

Hi,

My user management system is working fine.
I have created a User model class and CRUD functionality by using Gii, and it is working fine.

Now I am kind a lost here, I want to save some information to User table from another controller.
In my TestController.php, I have a method testMethod() from which I want to save information to User table.

class TestController extends Controller
{
   public function testMethod()
   {
      $firstName = 'abc';
      $lastName = 'xyz';
      $email = 'test@test.com';

      // save it to User's table in database
   }



I have checked the UserController.php class, but it simply calls the save() method.

How can I save user from above method?

Thanks in advance.
0

#2 User is offline   PrplHaz4 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 107
  • Joined: 28-September 09
  • Location:Boston, MA

Posted 29 July 2013 - 08:25 AM

View Postrazor101, on 29 July 2013 - 07:48 AM, said:

Hi,

My user management system is working fine.
I have created a User model class and CRUD functionality by using Gii, and it is working fine.

Now I am kind a lost here, I want to save some information to User table from another controller.
In my TestController.php, I have a method testMethod() from which I want to save information to User table.

class TestController extends Controller
{
   public function testMethod()
   {
      $firstName = 'abc';
      $lastName = 'xyz';
      $email = 'test@test.com';

      // save it to User's table in database
   }



I have checked the UserController.php class, but it simply calls the save() method.

How can I save user from above method?

Thanks in advance.


save is a method of User (inheriting from CActiveRecord) - so, create a new instance of User, initialize the variables you have defined, and use the power of activerecord to save it to the db ($user->save()).

$user = new User;

$user->firstName = $firstName;
$user->lastName = $lastName;
$user->email = $email;

$user->save();



1

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