Skip to content

Instantly share code, notes, and snippets.

@carlossg00
Created March 10, 2011 18:58
Show Gist options
  • Save carlossg00/864664 to your computer and use it in GitHub Desktop.
Save carlossg00/864664 to your computer and use it in GitHub Desktop.
<?php
namespace Acme\BlogBundle\Controller;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpFoundation\Response;
use Acme\BlogBundle\Entity\Post;
class DefaultController extends ContainerAware
{
/**
* @extra:Route("/", name="blog_home")
* @Template
*/
public function indexAction()
{
$em = $this->container->get('doctrine.orm.default_entity_manager');
$posts = $em->createQuery('SELECT p FROM BlogBundle:Post p')->getResult();
return array('posts' => $posts);
//return new Response("Hello Symfony2");
}
/**
* @extra:Route("/view/{id}", name="blog_view")
* @extra:ParamConverter("post", class="Acme\BlogBundle\Entity\Post")
* @extra:Template
*/
public function viewAction(Post $post)
{
return array('post' => $post);
}
}
Posts list
<table>
{% for post in posts %}
<tr>
<td><a href = "{{ path('blog_view' , {'id': post.id}) }}">{{post.author}}</a></td>
<td>{{post.title}}</td>
<td>{{post.content}}</td>
</tr>
{% endfor %}
</table>
<a href="{{ url("blog_home") }}">Home</a>
<h1>{{post.title}}</h1>
<p>{{post.content}}</p>!
@carlossg00
Copy link
Author

Hi All,

Just playing with basic FrameworkExtraBundle features, from the Acme Blog example, created viewAccion that it's called but expecting 'post' argument:

Controller "Acme\BlogBundle\Controller\DefaultController::viewAction()" requires that you provide a value for the "$post" argument (because there is no default value or because there is a non optional argument after this one).

ParamConverter not working as expected, typo?
Really don't know
Any help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment