PHP code example of bear / reactjs-module
1. Go to this page and download the library: Download bear/reactjs-module library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bear / reactjs-module example snippets
$distDir = dirname(__DIR__, 2) . '/var/www/dist';
$this->install(new ReduxModule($distDir, 'ssr_app');
use BEAR\Resource\RenderInterface;
use BEAR\Resource\ResourceObject;
use Ray\Di\Di\Inject;
use Ray\Di\Di\Named;
class Greeting extends ResourceObject
{
/**
* @Inject
* @Named("ssr_app")
*/
public function setRenderer(RenderInterface $renderer)
{
$this->renderer = $renderer;
}
public function onGet()
{
$this->body = [
'title' => 'Greeting',
'hello' => ['message' => 'konichiwa']
];
return $this;
}
}
/* @var $ssr \BEAR\ReactJsModule\Ssr */
$view = $ssr->render(['hello']);
return <<<"EOT"
<!doctype>
<html>
<head>
<title>{$ssr->escape('title')}</title>
</head>
<body>
<div id="root">{$view->markup}</div>
<script src="build/react.bundle.js"></script>
<script src="build/app.bundle.js"></script>
<script>{$view->js}</script>
</body>
</html>
EOT;
$this->install(new FakeV8Module(new ReduxModule($distDir, 'ssr_hello')));