Dite Gashi
Dite Gashi

Reputation: 128

Create a form example in Yii

I've been struggling with creating a simple form that will later store data in the database, using Yii framework and none of the tutorials I have been following have been explanatory enough. The idea is that I am editing an existing Yii project and I need to add user registration functionality to the following project. So Gii is out of the option.

To my understanding I have created:

What is the general idea that I should follow in order to create a form in the view, and add data from that form on the database?

On the controller so far I have:

class UserController extends LSYii_Controller {


public function actionIndex() {  }}

The model:

public static function insertUser($new_user, $new_pass,$new_full_name,$parent_user,$new_email)
{
    $oUser = new self;
    $oUser->users_name = $new_user;
    $oUser->password = hash('sha256', $new_pass);
    $oUser->full_name = $new_full_name;
    $oUser->parent_id = $parent_user;
    $oUser->lang = 'auto';
    $oUser->email = $new_email;
    if ($oUser->save())
    {
        return $oUser->uid;

    }
    else{
        return false;
    }
}

and on the view I have nothing since I am not sure on how to proceed. Any help will be greatly appreciated.

Upvotes: 0

Views: 3685

Answers (1)

David Newcomb
David Newcomb

Reputation: 10943

One of the nice things about Yii is it's plugin architecture. There is a user registration and management module that will do all of this for you. It's free and available from:

http://yii-user.2mx.org/

Features:

  • Login from User Name or Email
  • Registration
  • Activation accounts (verification email)
  • Recovery password (send recovery key to user email)
  • User profile page
  • Manage Users
  • Manage Profile Fields
  • Profile field widget for view, edit and save data (FieldWidget)
  • Date widget (jQueryUI datepicker)
  • File upload widget
  • Profile Relation Widget
  • API

You can edit the User class to add other fields or store those additional fields in another table if you didn't want to mess with the yii-user code/configuration.

Upvotes: 1

Related Questions