Skip to content

Instantly share code, notes, and snippets.

@k-holy
Created July 20, 2012 09:51
Show Gist options
  • Save k-holy/3149937 to your computer and use it in GitHub Desktop.
Save k-holy/3149937 to your computer and use it in GitHub Desktop.
BEAR.Sundayはじめてのページリソース
<?php
namespace sandbox\Resource\App\First;
use BEAR\Resource\AbstractObject;
/**
* Greeting resource
*/
class Greeting extends AbstractObject
{
/**
* Get
*
* @param string $name
*
* @return string
*
*/
public function onGet($name)
{
return sprintf('Hello, %s', $name);
}
}
<?php
namespace sandbox\Resource\Page\First;
use BEAR\Framework\Resource\AbstractPage;
/**
* Greeting page
*/
class Greeting extends AbstractPage
{
/**
* Contents
*
* @var array
*/
public $body = [
'greeting' => ''
];
/**
* Get
*
* @param string $name
*/
public function onGet($name = 'World')
{
$this->body['greeting'] = sprintf('Hello, %s', $name);
return $this;
}
}
<?php
namespace sandbox\Resource\Page\First;
use BEAR\Framework\Resource\AbstractPage;
use BEAR\Framework\Inject\ResourceInject;
/**
* Greeting page
*/
class Greeting extends AbstractPage
{
use ResourceInject;
/**
* Contents
*
* @var array
*/
public $body = [
'greeting' => ''
];
/**
* Get
*
* @param string $name
*/
public function onGet($name = 'World')
{
$this->body['greeting'] = $this->resource
->get
->uri('app://self/first/greeting')
->withQuery(['name' => $name])
->request();
return $this;
}
}
<!DOCTYPE html>
<html lang="en">
<body>
<h1>{$greeting|escape}</h1>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment