Created
March 10, 2011 18:58
-
-
Save carlossg00/864664 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="{{ url("blog_home") }}">Home</a> | |
<h1>{{post.title}}</h1> | |
<p>{{post.content}}</p>! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?