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

URL canonicalization fails for persistent components #545

Closed
tomaswindsor opened this issue Feb 19, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@tomaswindsor
Copy link
Contributor

commented Feb 19, 2012

Default values of persistent parameters of persistent components are only considered for components that were created in startup method of the presenter (or before). Lazily created components (or those created in action or render methods) are ignored. This causes canonicalization of URLs containing parameters of non-startup created components to fail.

General workaround is to call method saveGlobalState (which instantiates all persistent components) from startup.

@dg

This comment has been minimized.

Copy link
Member

commented Mar 30, 2013

Can you provide example code?

@tomaswindsor

This comment has been minimized.

Copy link
Contributor Author

commented Mar 30, 2013

Consider following presenter with persistent variable $baz with default value 123, and subcomponent Foo which has persistent variable $bar also with default value 123. I.e.:

/**
 * @persistent(Foo)
 */
class FooPresenter extends BasePresenter
{
    /**
     * @var string
     * @persistent
     */
    public $baz = 123;

    public function createComponentFoo()
    {
        return new FooControl;
    }
}

class FooControl extends Nette\Application\UI\Control
{
    /**
     * @var string
     * @persistent
     */
    public $bar = 123;

    public function render()
    {
    }
}

Consider also using default router.
Now url with query string like ?baz=123 will be automatically canonicalized into empty query string.
But query string ?foo-bar=123 won't trigger canonicalization.
And finally query string ?baz=123&foo-bar=123 will trigger canonicalization to ?foo-bar=123.

But when we call saveGlobalState from FooPresenter::startup:

    public function startup()
    {
        parent::startup();
        $this->saveGlobalState();
    }

... described behavior will change and canonicalization will work as it should even for subcomponents, i.e.:
?baz=123&foo-bar=123 will be canonicalized into empty query string.

@dg dg closed this in 958120f Dec 19, 2013

dg added a commit that referenced this issue Dec 19, 2013

UI\Presenter: auto-loading components moved from saveGlobalState() to…
… signal phase, before canonicalize() [Closes #545]

dg added a commit that referenced this issue Dec 19, 2013

UI\Presenter: auto-loading components moved from saveGlobalState() to…
… signal phase, before canonicalize() [Closes #545]

dg added a commit to nette/application that referenced this issue Mar 13, 2014

dg added a commit to nette/application that referenced this issue Mar 13, 2014

dg added a commit to nette/application that referenced this issue Mar 20, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.