This commit is contained in:
Tomas Husak 2021-07-22 10:26:54 +02:00
Родитель a3819c4c54
Коммит fcc30f2ab3
1 изменённых файлов: 20 добавлений и 0 удалений

20
docs/context-lifetime.md Normal file
Просмотреть файл

@ -0,0 +1,20 @@
# PHP context lifetime
PHP context usually terminates with the PHP script execution. It is the standard behavior of PHP. However, we can utilize PeachPie and Blazor to save the context on a client side to save the application state.
> An example can be seen in [https://github.com/peachpiecompiler/peachpie-blazor/tree/dev/docs/src/Tests/Examples/AllTogether](https://github.com/peachpiecompiler/peachpie-blazor/tree/dev/docs/src/Tests/Examples/AllTogether), where we utilize the persistent context for saving data from many parts of the application representing different PHP scripts.
You will change the context lifetime of the provider by setting the `ContextLifetime` parameter to `SessionLifetime.Persistant`. When a client navigates to another PHP script, the context of this script is the same as the previous one.
> The current implementation doesn't support more than one context at a time. So when there are two instances of the provider with different `ContextLifetime`, the context persistency will not work.
```razor
<PhpScriptProvider ContextLifetime="@SessionLifetime.Persistant" Type="@PhpScriptProviderType.ScriptProvider">
<Navigating>
<p>Navigating</p>
</Navigating>
<NotFound>
<p>Not found</p>
</NotFound>
</PhpScriptProvider>
```