User Registration And MVC

Rather a basic question, though i’m a bit confused with the architecture.

I am programming a website using Yii framework.

There is a SiteController and AdminController (built not by me).

All the site administration is in AdminController, and the user interaction in SiteController.

I know it is not correct as it is not model-based.

Now, I want to implement user registration. The user can signup and administrator can change his properties.

Is it better to build UserController or manage all the above in the existing controller (not breaking previous logic)?

You’re free to do it whatever way you want. You can either create a model/crud for your users entity (table) as a starting point and use the generated UserController to handle your registration form (the create action pretty much is a basic registration form, if you allow access to unidentified users) or create just the model using Gii and then manually add an action to the SiteController to handle a registration form.

You could also use one of the many user management extensions built for yii. There’s a wiki entry on using yii-user-management module:

As you may have noticed, gii will generates CRUD codes for a specified CActiveRecord model. The generated codes of the controller and the views are tightly connected to the target model.

But you don’t have to limit the scope of a controller to a specific model. You can handle any models in your specific controller. I mean, in one of your front-end controller actions you can access the User model that is defined in the back-end(admin) part.

Or, in your specific case, you may create some special CFormModel to handle user registration in which you can access the User model.

If the back-end part is not built in yii way, i.e. if you don’t have the appropriate CActiveRecord model for User in the back-end, then you may want to create a CActiveRecord model of your own. The back-end will access the user table in a traditional way, and you will access the same table in yii way. I think there’s no harm in it, though it’s not a good implementation as a whole.