class DefaultController extends Controller
{
public function indexAction()
{
$client = new Client($this->container-> getParameter('backend_host'));
$request = $client->get('/node.json');
$response = $request->send()->json();
$recipes = array();
foreach ($response['list'] as $recipe) {
$recipes[] = $recipe;
}
return $this->render('LullabotRecipeBundle:Default:index.html.twig',
array('recipes' => $recipes));
{% extends '::base.html.twig' %}
{% block body %}
{% for recipe in recipes %}
-
{{ recipe.title }}
{% endfor %}
{% endblock %}
$form = $this->createFormBuilder()
->add('title', 'text')
->add('body', 'textarea')
->add('prep_time', 'integer')
->getForm();
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
$data = $form->getData();
$client = new Client($this->container->getParameter('backend_host'));
$client->addSubscriber(new OauthPlugin(array(
'consumer_key' => $this->container->getParameter('oauth_consumer_key'),
'consumer_secret' => $this->container->getParameter('oauth_consumer_secret'),
)));
$request = $client->post('/api/node', null, array(
'title' => $data['title'],
'body' => array('und' => array(array('value' => $data['body']))),
'field_recipe_prep_time' => array('und' => array(array('value' => $data['prep_time']))),
'type' => 'recipe'
));