Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ViewModel loses data when you change view #1479

Closed
Altreus opened this issue Jul 11, 2013 · 4 comments
Closed

ViewModel loses data when you change view #1479

Altreus opened this issue Jul 11, 2013 · 4 comments

Comments

@Altreus
Copy link
Contributor

Altreus commented Jul 11, 2013

I had a bash at fixing this but it's Jelmered. The set_view method doesn't accept the view to which to set it, but merely forges a new View out of the string you set.

This means that the way you change view

$this->_view = 'new/view';
$this->set_view()

has already destroyed all data information on the original View object, so it can't be sent to the new one.

Options seem to me to be:

  • Change the way set_view() works so it works like any other mutator - this breaks BC but also allows changes from outside the class
  • Change the way set() works so that it stores the data on the ViewModel and passes it to the View at a later juncture - but this might require the user manually setting the data on the View object if they override, e.g., view().
@WanWizard
Copy link
Member

Just to check: you want to create a ViewModel with a view name string, then later change the View by a new one, but retain all data set on the original view?

@WanWizard
Copy link
Member

And do you want to do this from inside the ViewModel, or from the outside?

If from the inside, you can just do
$this->_view->set_filename('new/view');

@Altreus
Copy link
Contributor Author

Altreus commented Jul 18, 2013

It is from the inside yes - I suppose the way to do it in general would therefore be to have a method that changes the view filename from the outside. Is this valuable? Would it be better do this ad-hoc, for ViewModels that have rendering options?

@WanWizard
Copy link
Member

This has been addressed in 2.0, where both View and Presenter are extensions of the generic DataContainer class, so data is stored separate from the View instance. It's only passed to the view when it's rendered.

Implementing this for 1.x is going to be quite a change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants