when should I create new view in the same view controller and when should I create new view controller?
This is a generic question, without knowing what you are trying to do is difficult to tell you how to create an application. By the way, a little (and simple) explanation can be this.
Controllers must implement the logic of your application, they must "control" a particular feature of your application.
Views must show what the controllers want to show to the user.
So, if you want to create something with some kind of logic (user check / data loading and more) you have to create a controller, if you want to show to the user something you can create a view.
The difference between 1 or 2 controllers depends on you application, you have to create one single kind of logic use 1, otherwise if you have a big application with different feature then create N controllers.
The following is more of a guideline than a rule.
You need to create a new view controller when you want to modularize your code according to some parameters (I do it based on functionality). eg. DashboardViewController, SettingsViewController etc.
Inside a DashboardViewController we can have many things going on. Each of which might need a view to represent.
I think this is more subjective than objective. In one project I have, a new controller needs to be created anytime I need to change the tabbed navigation, or I'd end up with a mess of if/else in my onInit method that defines the tabs.
In other cases, it might be as simple as just asking yourself if it's a logical grouping. E.g. I have a UserController that manages adding/editing/removing users. Should I use that controller for login/logout/forgotPassword, or should I create an AuthController? Personally, I would separate it to an AuthController since the security for a UserController should be admins only while the AuthController lets anyone try to login. Then, when the user is logged in, do you do UserController for their profile or create a ProfileController since again there are permission differences. Any logged in user can manage their own profile, but that doesn't mean they should get access to my UserController.
However, you could put add/edit/delete/profile/login/logout/forgotPassword views into a single controller and just handle permissions on a per-view basis, and that wouldn't be "wrong". As long as you are keeping your business logic in your model and out of the controller, and keeping as much logic as possible out of your view...then you're already ahead of the curve and refactoring when you need to shouldn't be too hard.
If you find yourself doing a lot of if/else in your onInit where you are initializing based on which methods are being loaded...that would be a sign to me that you should probably look at creating a separate controller.
Related
In the app I'm working on it's a fairly big codebase and components/pages are sometimes based on user roles. Admins will be able to see certain buttons or sections while regular users are not.
I need to modify a lot of the existing pages/components to accommodate a new role that's being added, which is view-only-admin.
This role will only be able to see everything including calendars, tasks, etc. but they are not allowed to make any sort of updates.
It would be a tremendous amount of work to go through the template of each component and file and look for v-if admin and also add a view-only-admin as well as make every single button or submit/click method behave differently for a view-only-admin role.
What would be the best way to handle this for the entire app? Re-writing and modifying v-if and submit methods seem like a bad use of time.
I've only been working with Vue/Nuxt for a few months, but I have read Mixins are pieces of code that you can reuse.
Would it be possible to write a mixin so that if the role is "view-only-admin" and there's an action that is a put/Post call, then they are not able to perform those API calls and presented with an error message?
I'm not sure how to go about properly implementing this feature. If I am able to stop all PUT/POST calls using a mixin, it would just redirect to a 404 right?
Thoughts?
If you are using axios for POST/PUT methods, then you should definitely check Interceptors.
But if you add only an interceptors without UI updates - your users may be confused why some buttons exist but doesn't work as expected.
Currently I build an application which uses silhouette for authentication. Every user should be able to authenticate via different providers.
Actually I cant figure out how to implement "silhouette" since the Identity trait only includes a single LoginInfo instead of a Sequence of LoginInfo. Is there any way around it or does someone know how to implement this or even better knows an example project which implemented it that way?
Thanks in advance..
You will need to create a separate case class for User. Lets call it DBUser.
This case class will contain a field with a list of LoginInfos. Once you know which LoginInfo you should use in UserService, you will need to cast DBUser into User (the one that extends Identity) with the corresponding LoginInfo.
I am in the process of developing an ASP.NET MVC4 application where one of the requirement is to allow the administrator of the application to add additional data capture fields in the screens. What would be the best approach to address this?
There are different approaches.
First we have to note, that the Model itsself should be strongly typed. That leaves you with the option to put your dynamic data into the Viewbag. Therefor you should put your second model, or dynamic model, which is not type of your first trongly typed model, into the ViewBag in your Controller action.
The second option is putting your additional datafields, which the administrator can add to the view or hide in the view into your strongly typed ViewModel, and just let the administrator tinker with the visibility of the fields.
In addition to that, you could generate two views for 1 action, one which the basic datafields and one with the full set.
Kind regards
I want to create custom context in OpenERP. Need something like polish notation in domain with '|'. Need also hierarchial like 'region_id','child_of','region_id.parent_id'. is it possible?
thanks :)
As far as I know, you can dump any data you want into the context, and it's up to the server-side code to interpret that data. The only time I've run into trouble with context was when two screens used the same key in context but put conflicting data there. Then visiting one screen would break the other screen.
I'm writing an "Account" module which should take care of everything about accounts: registration, login/logout, user administration, password recovery, account activation, etc.
So I thought it would be best to reuse whatever the module's DefaultController::actionRegister() generates to show on the main page.
So my question is: how to create a new "sub request" (similar to CController::forward()) from any controller (either SiteController, read: from views/layouts/main.php, or another controller, eventually of another submodule) to a given module/controller/action?
I've tried with $this->forward() from within my application layout without success: it shows a blank page, no error whatsoever.
Thanks
You are trying to make a widget. Avoiding tightly coupled classes and actions will make your application more secure, easier to maintain and improve and far more reusable.
"Inline partial redirects" are never the answers to any question, at least in Yii.