Let's say I have a component

Notice: This thread is very old.
looky
Member | 99
+
0
-

..called from template via {control myComponent} and I want it to be able to check if the user is logged in on it's creation, and if he isn't, redirect to login page. So in presenter's createComponentMyComponent() I pass $this->getUser() to my constructor, save it to property, and check in attached() (because there I have a presenter to call redirect on).

This works fine, except for one small detail – it ends with 500 server error (on production, on dev it just throws AborException).

So, how do I achieve the requested functionality?

Majkl578
Moderator | 1364
+
0
-

Your component is created too late, trying to redirect while the template is already rendering. You'd have to enforce creating it sooner, e.g. in startup/action method, e.g. by calling $this->getComponent('myComponent') or just $this['myComponent'].
Also, technically you don't even need to pass User to the component – you can obtain it through Presenter#getUser().

looky
Member | 99
+
0
-

Yep, that's what I've figured out as well. Bummer, I was trying to avoid touching methods other than createComponent<name>. Thanks anyway.