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

Odd view behavior with layouts + pick #1933

Closed
aleemb opened this issue Jan 28, 2014 · 5 comments
Closed

Odd view behavior with layouts + pick #1933

aleemb opened this issue Jan 28, 2014 · 5 comments

Comments

@aleemb
Copy link

aleemb commented Jan 28, 2014

I noticed some odd behavior with calling setLayout() and pick().

1. $view->setLayout('fancy');
2. $view->pick('someview');
  1. Turns out if I call setLayout() then pick() then the setLayout() gets ignored. If there is a default layout, that gets picked which is worse since the framework ignores user intent (line 1).
  2. The work around right now is to call pick(['view', 'layout']). This behavior is undocumented and I gleaned it by reading the C source. Is this undocumented because it's unsupported and liable to change or is this okay to use?
  3. It would be nice to be able to fix this bug and leave out the undocumented array syntax since the code legibility is better and it allows full control to the user to compose views throughout the application lifecycle (set a main, a layout and a view at different stages of the app lifecycle).

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@iby
Copy link
Contributor

iby commented Jan 28, 2014

Are you on 1.3.0 branch?

@aleemb
Copy link
Author

aleemb commented Jan 28, 2014

Verified this issue on 1.2.5 and 1.2.6.

@iby
Copy link
Contributor

iby commented Jan 28, 2014

It's the same for 1.3.0. In view.c on line L1277 it seems to be storing the view into array along with the layout. Second time you set the layout, the internal value changes, but that stored layout in the array from earlier pick() doesn't.

@aleemb
Copy link
Author

aleemb commented Jan 28, 2014

I have overridden the pick() method in my custom View class that extends Phalcon\Mvc\View and the following change fixes the issue for me:

public function pick($renderView)
{
    return parent::pick([$renderView]);
}

@sergeyklay
Copy link
Contributor

Fixed in 2.1.x branch

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

No branches or pull requests

4 participants