Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
@coreymcmahon
coreymcmahon / app.php
Created April 28, 2012 06:32
Standard Symfony 2 front controller file for production environment - http://www.symfonycentral.com
<?php
// web/app.php
require_once __DIR__.'/../app/bootstrap.php.cache';
require_once __DIR__.'/../app/AppKernel.php';
//require_once __DIR__.'/../app/AppCache.php';
use Symfony\Component\HttpFoundation\Request;
$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
@coreymcmahon
coreymcmahon / app_dev.php
Created April 28, 2012 07:28
Front controller for a Symfony 2 project development environment - http://www.symfonycentral.com
<?php
if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
require_once __DIR__.'/../app/bootstrap.php.cache';
@coreymcmahon
coreymcmahon / BlogController.php
Created April 29, 2012 11:03
Basic Symfony Controller demonstrating the use of a logical name for template - http://www.symfonycentral.com
<?php
// src/MyCompany/BlogBundle/Controller/BlogController.php
namespace MyCompany\BlogBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class BlogController extends Controller
{
public function viewAction($id)
{
@coreymcmahon
coreymcmahon / gist:2549450
Created April 29, 2012 11:07
A Symfony action that redirects to another action using the logical name - http://www.symfonycentral.com
<?php
public function indexAction($name)
{
$response = $this->forward('MyCompanyBlogBundle:Blog:show', array(
'id' => 30
));
return $response;
}
@coreymcmahon
coreymcmahon / routing.yml
Created April 30, 2012 11:43
Importing an external routing.yml file from a bundle - http://www.symfonycentral.com
# app/config/routing.yml
mycompany_routes:
resource: "@MyCompanyBundle/Resources/config/routing.yml"
prefix: /mycompany
@coreymcmahon
coreymcmahon / routing.yml
Created April 30, 2012 12:11
Basic Symfony route for a contact page - http://www.symfonycentral.com
contact:
pattern: /contact
defaults: { _controller: MyCompanyBundle:Home:contact }
requirements:
_method: GET
@coreymcmahon
coreymcmahon / routing.yml
Created April 30, 2012 12:14
An exmaple of a complex Symfony routing rule from the official documentation - http://www.symfonycentral.com
article_show:
pattern: /articles/{culture}/{year}/{title}.{_format}
defaults: { _controller: AcmeDemoBundle:Article:show, _format: html }
requirements:
culture: en|fr
_format: html|rss
year: \d+
@coreymcmahon
coreymcmahon / ArticleController.php
Created April 30, 2012 12:43
Example of a controller class based on a complex route - http://www.symfonycentral.com
<?php
namespace Acme\DemoBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
class ArticleController extends Controller
{
public function showAction($culture, $year, $title)
{
@coreymcmahon
coreymcmahon / index.php
Created May 2, 2012 11:54
Ugly non-templated version of some dynamic view code - http://www.symfonycentral.com
<!DOCTYPE html>
<html>
<head><?php echo $this->title; ?></head>
<body>
<?php foreach ($this->article as $article): ?>
<?php echo $article->getBody(); ?>
<!-- and so on and so on... -->
<!DOCTYPE html>
<html>
<head>{{ title|raw }}</head>
<body>
{% for article in articles %}
{{ article.body }}
{# and so on and so on... #}