Skip to content

Instantly share code, notes, and snippets.

View helios-ag's full-sized avatar
🐈
On the internet nobody knows you're a cat

Al Ganiev helios-ag

🐈
On the internet nobody knows you're a cat
View GitHub Profile
@extolabs
extolabs / Form.php
Created May 12, 2011 16:19
Form Errors Symfony
private function getAllFormErrors($children, $template = true) {
foreach ($children as $child) {
if ($child->hasErrors()) {
$vars = $child->createView()->getVars();
$errors = $child->getErrors();
foreach ($errors as $error) {
$this->allErrors[$vars["name"]][] = $this->convertFormErrorObjToString($error);
}
}
@cordoval
cordoval / update_acl.rb
Created September 25, 2011 05:28 — forked from shaneog/update_acl.rb
Capifony Task to Set ACLs on Symfony2 app/cache and app/logs directories as per http://symfony.com/doc/current/book/installation.html
# Change ACL on the app/logs and app/cache directories
after 'deploy', 'deploy:update_acl'
# This is a custom task to set the ACL on the app/logs and app/cache directories
namespace :deploy do
task :update_acl, :roles => :app do
shared_dirs = [
app_path + "/logs",
@cordoval
cordoval / GroupBy.php
Created October 5, 2011 22:35 — forked from anonymous/GroupBy.php
Grouping filter for Twig.
<?php
namespace BlackRook\TaskBundle\Twig\Extension;
use DateTime,
Twig_Extension,
Twig_Environment,
Twig_TemplateInterface,
Twig_Error_Runtime,
Twig_Filter_Method;
@Ocramius
Ocramius / User.php
Created October 23, 2011 14:22
Doctrine 2 @OneToMany @manytoone example
<?php
namespace HelloWorld;
use InvalidArgumentException;
/**
* This class is somewhere in your library
* @Entity
* @Table(name="users")
*/
@merk
merk / blocks.html.twig
Created November 12, 2011 09:48
A way to deal with collections
{% block address_form %}
{% spaceless %}
<div class="address">
<a href="#" class="remove_item btn danger right">Remove</a>
{{ form_row(address.unitNumber, { "label": "Unit Number" }) }}
{{ form_row(address.streetNumber, { "label": "Street Number" }) }}
{{ form_row(address.street, { "label": "Street" }) }}
{{ form_row(address.city, { "label": "City" }) }}
{{ form_row(address.postcode, { "label": "Postcode" }) }}
<?php
$filter->add('editor', 'doctrine_orm_callback', array(
'field_type'=> 'text',
'callback' => function($queryBuilder, $alias, $field, $value) {
$val = $value['value'];
if(!$value || strlen($val) <= 0){
return;
@pitch-gist
pitch-gist / gist:2999707
Created June 26, 2012 22:21
HTML: Simple Maintenance Page
<!doctype html>
<title>Site Maintenance</title>
<style>
body { text-align: center; padding: 150px; }
h1 { font-size: 50px; }
body { font: 20px Helvetica, sans-serif; color: #333; }
article { display: block; text-align: left; width: 650px; margin: 0 auto; }
a { color: #dc8100; text-decoration: none; }
a:hover { color: #333; text-decoration: none; }
</style>
@nikic
nikic / guestbook.markdown
Created July 29, 2012 14:21
Quick doesn't have to mean dirty: Also applies to PHP!

Quick doesn't have to mean dirty: Also applies to PHP!

This is just a quick response to http://me.veekun.com/blog/2012/07/28/quick-doesnt-mean-dirty/. I won't bother to write a proper blog post for this, so a Gist will have to do ;)

When I read that article, one thing really striked me: If you want to quickly create a web app in PHP, you do exactly the same. I mean, exactly.

I never used the Silex microframework before, so I took this as a chance to see how it works. I'll just do the same as eevee did, only with a bit less commentary (this is a Gist after all!)

I hope that this will show you that PHP and Python are really similar to work with. Also this should show that just because you're using PHP, doesn't mean that you write dirty code. The similarity in the process and code is really incredible :)

@jmather
jmather / deploy.rb
Created August 30, 2012 05:51
Remove dev only files in production via capifony
set :dev_only_files, [web_path + "/app_dev.php", web_path + "/check.php", web_path + "/config.php"]
set :production, true
after 'symfony:cache:warmup', 'pff:productify'
namespace :pff do
desc "Remove app_dev.php, check.php and config.php from production deployment"
task :productify, :except => { :production => false } do
if dev_only_files
pretty_print "--> Removing app_dev.php, config.php, and check.php from web"
@jmather
jmather / SSLManagementListener.php
Created November 9, 2012 21:22
Redirect to SSL only on given
<?php
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernel;
class SSLManagementListener
{
private $domain;