Building my first web app using Yii and wondering if it is best to include the user registration process as part of my UserController or is it better to create a registrationController and keep the logic separate开发者_JAVA技巧d?
And ...on the same line of thought, would it be beneficial to have a profileController to handle additional user information, or just have the userController handle that as well?
Is a registration the creation of a User?
Similarly is a profile just a view or update of a User?
It seems like these could all fit one controller fairly well as basic CRUD operations.
In my opinion you can make it to the UserController
because the notion of registration is to create a new user. So I think you can make Register
same with Create
.
Actually, they are not very complex and could be in one controller. It is at least my own habit to include CRUD in one controller(Maybe my apps do not involve complex logic)
Does this form require the user to enter data that is not permanently stored in the dataabse? If so then you should create a new model derived from CFormModel rather than ActiveRecord. Your site controller can handle the launching of the CFormModel views which then take care of themselves (validation, ajax, whatever) if they don't need any dynamic interaction with server (LoginForm) or they can have a separate controller if more complex interaction is needed (RegisterForm). In a CFormModel you can access the user input during the session and process/store it however you like, but then it disappears when the user is done. See the LoginForm and RegisterForm for the blog demo, as example patterns. Does this form have as much dynamic data interaction with other models as it does with User (not just one-off cascading of relationships)? In that case it might be best to create that separate RegisterController you mention. That's what the blog demo does, and it's a pretty simple app. You can use gii to automatically create the CRUD interface for admin's and community moderators/managers from your User model. You can then customize it and renderPartial it whenever you want to reuse one of those views for a non-admin user. The validation rules in the models carry over too. Only guests and normally-privileged users need the dumbed down interface of a LoginForm and RegisterForm.
Good idea is to put user related stuff in module, so you could use it easy in different app. In that module you could put profile, or other user related controllers without clutttering app.
精彩评论