Skip to content

Instantly share code, notes, and snippets.

View janit's full-sized avatar

Jani Tarvainen janit

View GitHub Profile
Here used to be a rough prototype of an
implementation, which is now deprecated.
in favour of this:
https://www.symfony.fi/entry/sharing-state-in-a-symfony-hybrid-app-with-twig-react-etc
-----
Using this approach you can bootstrap a
React application on the server side using
PHP/Symfony so that your client application
<?php
$stateId = 3;
$stateService = $this->get('ezpublish.api.service.object_state');
$contentService = $this->get('ezpublish.api.service.content');
$contentInfo = $contentService->loadContentInfo(93);
$objectStateGroup = $stateService->loadObjectStateGroup(4);
c78e3b0f3d9244ed8c6d1c29464bdff9
<?php
/**
* @Route("/test",name="testroute")
* @Template
*/
public function testAction(Request $request, Checkout $checkout)
{
$repository = $this->get('ezpublish.api.repository');
cd /var/www/html/ezstudio/
php app/console assets:install --symlink
php app/console assetic:dump --env=dev
@janit
janit / test.html.twig
Created January 25, 2017 10:20
Sample Twig calls for PhpStorm indenting example
{{ render_esi(
controller(
"Foo:Default:bar",
{
'bar': foo,
}
)
) }}
<?php
namespace AppBundle\State;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class AppState implements \JsonSerializable {
public $fetchMore = false;
<?php
public function indexAction(Request $request )
{
$appState = new AppState();
$em = $this->get('doctrine.orm.default_entity_manager');
$apartments = $em->getRepository('AppBundle:Apartment')->findByLimit(3);
$appState->setApartments($apartments);
$appState->setFetchMore(true);
<h2>Hello from Twig</h2>
<table>
{% for apartment in appstate.apartments %}
<tr>
<td>
{{ apartment.streetaddress }}<br />
{{ apartment.city }}<br />
{{ apartment.zipcode }}
</td>
<td>{{ apartment.country }}</td>
<script type="text/javascript">
var initialAppState = {{ appstate_serialized|raw }};
</script>
<script src="{{ asset('bundles/app/js/vue/vue.js') }}"></script>
<script src="{{ asset('bundles/app/js/vue/app.js') }}"></script>