Skip to content

Instantly share code, notes, and snippets.

View brikou's full-sized avatar

Brice BERNARD brikou

  • Nancy, France
View GitHub Profile
a) Importing the namespace only
<?php
use Symfony\Component\Form
class ContactForm extends Form\Form
{
protected function configure()
{
$this->add(new Form\TextField('subject', array(
<form method="post" action="..." {{ form.enctype }}>
{{ form.errors }}
{% for field in form.visible_fields %}
{{ field.label('My label') }}
{{ field.errors }}
{{ field.widget }}
The ID of this field is: {{ field.id }}
And the value: {{ field.value }}
{% endfor %}
<?php
protected function _editAction(Post $post)
{
$em = $this->get('doctrine.orm.default_entity_manager');
$factory = $this->get('form.factory');
$form = $factory->create(new PostFormType());
$form->setData($post);
if ($this->get('request')->getMethod() === 'POST') {
@everzet
everzet / symfony_resource_watcher.php
Created March 25, 2011 19:21
New ResourceWatcher component demonstration
<?php
use Symfony\Component\ResourceWatcher\ResourceWatcher,
Symfony\Component\ResourceWatcher\Event\Event,
Symfony\Component\Config\Resource\DirectoryResource,
Symfony\Component\Config\Resource\FileResource;
$watcher = new ResourceWatcher();
$watcher->track(new DirectoryResource('/some/directory'), function($event) {
@darrenderidder
darrenderidder / bashpath.sh
Created May 16, 2011 15:24
Get path of running script in bash
#!/bin/bash
# A simple test script to demonstrate how to find the
# "absolute path" at which a script is running. Used
# to avoid some of the pitfals of using 'pwd' or hard-
# coded paths when running scripts from cron or another
# directory.
#
# Try it out:
# run the script from the current directory, then
@tj
tj / Makefile
Created January 12, 2012 04:56
Stylus web service makefile example
STYLES = $(wildcard stylesheets/*.styl)
CSS = $(STYLES:.styl=.css)
COMPRESSED = $(CSS:.css=.min.css)
all: $(CSS)
style.min.css: $(COMPRESSED)
@cat $^ > $@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Responsive Design Testing</title>
<style>
body { margin: 20px; font-family: sans-serif; overflow-x: scroll; }
.wrapper { width: 6000px; }
.frame { float: left; }
h2 { margin: 0 0 5px 0; }
@weaverryan
weaverryan / forms.html.twig
Created April 13, 2012 11:26
Some basic Twitter Bootstrap Symfony2 form customizations
{# for twitter bootstrap specifically #}
{% block field_row %}
{% spaceless %}
<div class="control-group {% if errors|length > 0 %}error{% endif %}">
{{ form_label(form, label|default(null)) }}
<div class="controls">
{{ form_widget(form) }}
{{ form_errors(form)}}
</div>
</div>
@avalanche123
avalanche123 / timeout.php
Created July 10, 2012 19:12
timeouts in php
<?php
class TimeoutException extends RuntimeException {}
class Timeout
{
private $active;
public function set($seconds)
{
@chanmix51
chanmix51 / create-pomm-silex.sh
Last active February 25, 2018 17:11
Silex project bootstrap with Pomm
#!/bin/bash
mkdir -p bin sources/{config,twig,sql,lib/{Model,Controller}} web/{css,images,js} tests documentation log
chmod 777 log
> web/favicon.ico
cat > bin/generate_model.php <<"EOF"
<?php // bin/generate_model.php
$app = require(__DIR__."/../sources/bootstrap.php");