What is the best practice of propagating variable value in Yii - variables

I have a menu which pass parameters when a user click on one of the items menu.
When a user click an item menu, a view is lauched and call another view which call another view...
Can you tell me what is best practice on passing parameter from view to view.
Do I have to pass from view 1 to view2 and so on ..(as I did but I dont find it very clean) or it is another better way to do this.
I must say that I cannot put the value at the tpp of my controller because at that moment I do not know which menu wil be clicked.
Thanks for your reponse

I assume you are talking about views inside other views http://www.larryullman.com/2011/02/15/rendering-view-files-in-yii/ otherwise the question does not make a lot of sense.
The view has access to all the controller variables. So you can define a variable for the controller and you will be able to access it all the time in any of the nested views with $this->variable. You can actually put it at the top of the controller because that never changes while you are creating the views. That is 1 request, it should not change while you are processing the views.
If you are trying to make some ninja html, creating html with ajax based on what multiple menus the user clicks you can always save something in the session/cache and use that part but cleaner is to pass the argument through the entire process.

Related

Cocoa : Detect changes to any form element

I have a form built in interface builder.
Now I want to receive a notification when any element that is a child of a particular view is changed (be it text, or the select element, or a checkbox, etc).
Basically I want to know whether or not the form is "dirty" (changed).
How can I accomplish this?
One simple answer is to connect those UI elements which might change the value of the data model to an IBAction in the parent view controller. In that IBAction you can decide if you want to save the data, present a dialog, etc.

Two views displaying live data at the same time

I have two view controllers which should work like described below:
First view controller displays a view which has a table in it. The table contains data which is constantly changing. I have a delegate method for reloading the data when a change occurs. So that is taken care of. When the user selects a row in the table I would like to display a second view which would also contain live data in text format (one UITextView which would constantly change).
I would like to allow the user to access view 1 while view 2 would still be monitoring and displaying live data and vice versa. While user is on view 2, view 1 should still be monitoring and displaying any changes in the table content.
I guess its like having two view controllers present at the same time and switching between them.
What is the easiest or the most standard way to accomplish this? I dont mind if its all done programatically.
It's a little hard to tell what you're asking here. First, views shouldn't be processing data at all -- they should only be displaying it. It sounds like what you're describing is having a background process that updates to your second view. That process could certainly be running while your table is on screen, and when you switch to the second view, you can update it using this running process. Exactly how you would do this depends on the details of what you're trying to do. So, I think we could help you better if you provide more context on what kind of process you want going on that updates your second view, and how choosing a row in your table affects that process.
After Edit:
You can certainly do what you want to do. I think the main thing is that you need to have a property (typed strong) in your first view controller that points to your second view controller, so that when you go back to the second controller a second time, it goes back to the same instance. Based on the selection from the table, you can start whatever process you need to populate your text view, and that process can keep running even after you go back to the table view, since that controller won't get deallocated when it's view goes off screen (due to the strong reference you have). You would just have to have some sort of if clause in your second view controller to know whether the user has selected the same row again, and if so, just show the updated text view, rather than starting a new process.
That's about as specific as I can be without more detail from you.
what you have is a problem where you need a custom parentviewcontroller
look into splitviews as one example :: SplitView like Facebook app on iPhone
cool intros of how to do custom container view controllers :: Container View Controller Examples

Re-initialize view controller, or create separate view controllers for image capturing process?

I have created a custom camera overlay to capture an item, but my app requires that I go through the capturing process twice, so basically, once the user has taken the picture of the front of an item, they need to take the picture of the back of that same item, back to back. At the moment I am re-initializing the same view controller after the first picture has been taken, but I have read that it would be better practice to create a separate view controllers for each "step".
Which would be the better option, separate view controllers, or one view controller that gets re-used, as and when is needed?
I am quite new to Objective-C, so I am not sure if I have phrased everything correctly, I hope that I was able to adequately convey my problem.

How to access methods/variables from swapped custom view

I've created a window that contains an NSSplitView in which case the right custom view has a view that I swap into at runtime. The custom view swapped in contains a NSTableView with data inside it. I have a search box in the main window of the application that I want to be able to constrain the rows of the table view with.
I have the code to do this and I know it works, but the code I have was tested with a search text box and table view that were on the same window scope. With the text search box now being in the main window and the table view being in a different custom view, I'm not sure how to get the text search box to call the relevant methods from the custom view's controller class, because I don't have direct access to these method anymore.
I'm sure this is a very beginner question, but any help would be appreciated. Thanks.
Have your main window controller pass the search query or filter predicate to a property of the content view controller.
You can give the main window controller a weak-referencing (assign) property that holds the current content view controller. Implement a custom setter that not only assigns to the backing instance variable, but also does the swap. That, any time it's time to do a swap, you simply say self.currentContentViewController = viewControllerToSwapIn, and when it's time to change the query/predicate, you pass it to self.currentContentViewController.searchQuery (having implemented the searchQuery property in the MainContentViewController class and made all your actual content-view controllers inherit from that class).

Not getting viewDidLoad or Appear when switching tabs -- can I use NSNotification?

When I switch tabs in my tab bar application, one of my views needs to update because the user may have changed a preference that affects it. It is a UIViewController's view, but when the views switch, the viewDidLoad/Appear methods aren't called. Can this be solved using an NSNotification or any other way? Please give example code, especially for NSNotifications, as I am new to them.
You might want to peek at UITabBarControllerDelegate and tabBarController:didSelectViewController:. There you can determine how to handle the view change and whether you need to update the view based on the possible preference change.
tabBarController:didSelectViewController: you can implement this method in the appdelegate.
you will get the sxact root view controller at which yopu clicked . then you can update that view .