i have one simple question. I am building an app in Xcode 5. Part of the app is the typical login screen and the register screen and a database which stores username and password. My problem is that i don't want to write Sqlite code in both screens (in both view's controllers). What i want is to have the "databaseViewController.h and .m" controlling both the login controller and register controller. My question is : How do i do that? Im not asking for code, but short similar examples would be very helpful!. I am using storyboards if that helps too
What i want is to have the "databaseViewController.h and .m" controlling both the login controller and register controller
A common approach is to move the data access stuff out of your view controllers and into a data model (that's the M in MVC) that both view controller can talk to. Your model would have method to log in, register, tell you whether the user is already registered, etc. That leaves your view controllers to do what they do best: manage their respective view graphs and deal with user input. Maybe you already have some sort of data model, in which case the user registration and login functions can just be added to it. Otherwise, have your app delegate set up your model when the app starts up and share it with the view controllers that need to know about it.
To answer your question indirectly: If your goal is simply to share code between these two screens, you may find it easier to extract that code into a separate class, like AuthenticationManager or something, which you then use from your two different view controllers.
One common pattern for shared service objects like this is to hang them off of your application delegate. That is, add a property (e.g. authManager) to AppDelegate and then in your view controller(s), access it as [UIApplication sharedApplication].delegate.authManager.
Related
I only started with this a couple of days ago, so this may be a silly question...
I have an admin area with its own directory "admin" within the controller folder. So if the user is in the admin area, I want a sidebar to show. But obviously there will be a fair few "pages" (controllers) within the admin area. I have Clients, Services and Dashboard.
In the sidebar (on all pages) I want a list of clients and services so when clicked, it goes to a page and display info for that client/service.
I sort of have it working with add_service(), edit_service(), view_services() etc... but in each of these methods, it seems like I need to load services AND clients models, and pass the data back to each view... in all methods? So if I want to add a service, I click "add service" and it takes me to the add_service(). Do I need the below 4 lines in each method?
$this->load->model('client_model');
$this->load->model('services_model');
$data['clients'] = $this->client_model->get_clients();
$data['services'] = $this->services_model->get_services();
I have read about widgets, but not sure if that's what I need exactly.
Thanks
As you read, all you need is HMVC. This will create a "widget" with your controller, model and views, and you'll be able of calling "a whole": A part of the website wich manage its own part.
One solution is implement https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc into your code, you create a module called "client", and in your "admin" controller you call it. You'll get your client table there, and in your controller "client" you'll be able of call it too, and you'll have exactly the same behaviour. I've implemented wiredesignz HMVC quite times and I think is the solution for your trouble. Anyway, you could also check https://github.com/Bigwebmaster/codeigniter-modular-extensions-hmvc, which is a fork with improvements into the code.
About your sidebar, you'll have to call the widget you'll create with your clients, and you'll have it quickly with only one call, because the module will manage all the behaviour
I'm making a JAVAFX application in which I first want users to log in (in the very first prompted window) and, depending on the success or not, I want to create a different huge window which will be the global interface of the app.
I try to do it following the MVC pattern, though in JavaFX it does not seem to be a very clear separation. I have the views (two xml files), one controller (for both the views and the model) and the model.
Since the very first scene is always created in the main class, how can I hide that one and create a new one (corresponding to the global interface) when the user presses the login button??
Thank you very much in advance!
Basically all I want to do is, instead of creating 2 unique views for the admin and user interface, I only want to display the CRUD controls next to the items when the admin IS logged in.
Now the way I am currently doing it is checking the Auth session status and echoing out the controller links IF the Auth session has be activated..
But I wanted to know if there are any other (maybe better) approaches anyone might like to suggest.
I understood your question perfectly.
There are, as you realise, several approaches to this all with their pros and cons.
If you want to show the disabled controls, then you'll need to do something like what you already have.
I think I'd be more inclined to separate the views. This approach will allow you to style the view profile and edit profile views individually, perhaps better reflecting public and admin styles. You'll still need to check the Auth, of course.
I am new to GWT and getting back to programming after long gap...my question is about MVP implementation in GWT, I have gone through the following post and they were quite helpfull, but i still have some doubts
What are MVP and MVC and what is the difference?
What's your recommendation for architecting GWT applications? MVC, MVP or custom messaging solution?
i think the GWT tutorial (http://code.google.com/webtoolkit/articles/mvp-architecture.html) of MVP also has contoller (AppController ) in place and some of the responses are managed at Contoller level not at presenter. So my question is what should be the role of Controller in MVP pattern implementation?
From where should we initiate the async server call, presenter or controller , say if i have to save the record should i call the server function (which calls the DAO and saves the record) from Presenter or should presenter post event using event bus and conroller act on the event and calls server function for saving.
The GWT tutorial page you linked to says about the AppController:
To handle logic that is not specific
to any presenter and instead resides
at the application layer, we'll
introduce the AppController component.
So it's the glue between multiple Presenters, Views and the Model (maybe multiple Models). It also handles the browser history. And maybe additional things that aren't specific to one presenter.
As for the server call: There are several options, but I personally wouldn't do it from the view, and also not from the presenter - I'd use a model listener. The reason is, that multiple views and presenters can work together on one model. And when they change the model, that change should be sent to the server. Maybe you don't want to do that immediately, but collect a few changes before you send them. In that case, you could have a timer that's set up - well - by the AppController.
Answering to your last paragraph, I would say you should do it in presenter if there is something (some button) on view that is supposed to do it. Presenter is logically strongly tied to view (technically it should be weakly tied, by interfaces only not by implementations). If you want to save the record on some action which is not explicitly called from view, I wouldn't do it in presenter.
I'm new to OOPHP and frameworks at all.
I'm just wondering...
I have few controllers:
dashboard
signup
login and few more
I've put them into users directory. Everything is working correctly, I'm just wondering if I should put everything in one controller and signup, etc. should be a method of users controller? Or am I doing it correct way?
Regards,
M
It's totally up to you. The stuff you currently have could probably all go into one controller (user controller in this case), but it can build up to request the separation you already have, e.g. separate controller for each action, grouped by a prefix.
Good thing about kohana is that it allows you to do stuff like this the way you want to, there isn't a single guideline about putting many 'common' actions into the same controller; do it as you like / find appropriate.