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 | |
# src/MyCompany/BlogBundle/Controller/ArticleController.php | |
namespace MyCompany\BlogBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
class ArticleController extends Controller | |
{ | |
public function viewAction($id) | |
{ |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
{# title has been passed from the controller as an argument to 'render' #} | |
<title>{{ title|raw }}</title> | |
</head> | |
<body> | |
<nav> | |
<ul id="navigation"> | |
{# Here navigation is an array of arrays... #} |
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
{# app/MyCompany/BlogBundle/Resources/views/layout.html.twig #} | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>{% block title %}{% endblock %}</title> | |
</head> | |
<body> | |
<div id="content">{% block content %}{% endblock %}</div> | |
</body> | |
</html> |
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
{% extends 'MyCompanyBlogBundle::layout.html.twig' %} | |
{% block title %}{{ article.title }}{% endblock %} | |
{% block content %} | |
{{ article.body }} | |
{% endblock %} |
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
{# In the parent template #} | |
{% for item in navigation %} | |
{% include "navigation.html.twig" %} | |
{% endfor %} | |
{# In 'navigation.html.twig' #} | |
<a href="{{ item.href }}">{{ item.title }}</a> |
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 | |
# src/MyCompany/BlogBundle/Controller/ArticleController.php | |
namespace MyCompany\BlogBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
class ArticleController extends Controller | |
{ | |
/** | |
* @Route("/article/{id}", name="_view_article") |
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\Entity; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Acme\BlogBundle\Entity\Article | |
* | |
* @ORM\Table() | |
* @ORM\Entity |
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 MyCompany\BlogBundle\Controller; | |
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
/* Note below: we NEEED to include the Entity class Doctrine built for us */ | |
use MyCompany\BlogBundle\Entity\Post as 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
{% if title == '' %} | |
{# | |
If the title is empty, the controller didn't pass us | |
what we were expecting :( | |
#} | |
Please provide a valid ID | |
{% else %} | |
<h1>{{ title|raw }}</h1> | |
<p>{{ body|raw }}</p> | |
{% endif %} |
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
{# | |
This is a VERY basic form with two fields, which we'll | |
use to create the object to insert into the database. | |
#} | |
<form action="" method="POST"> | |
{# | |
Note: we normally wouldn't construct a form like this in | |
Symfony, as Symfony provides us with a WHOLE framework | |
dedicated to forms. |