Skip to content

Instantly share code, notes, and snippets.

View smottt's full-sized avatar

Metod smottt

View GitHub Profile
@smottt
smottt / MyType.php
Created November 12, 2012 12:50
CallbackValidator example 2.1
<?php
namespace Acme\DemoBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
use Symfony\Component\Form\Event\DataEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
configoptions="
--with-config-file-path=/etc/php53 \
--with-config-file-scan-dir=/etc/php53/php.d \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-cli \
--with-pear \
--with-openssl=/usr \
--with-iconv \
configoptions="
--with-config-file-path=/etc/php54 \
--with-config-file-scan-dir=/etc/php54/php.d \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-cli \
--with-pear \
--with-openssl \
--with-iconv \
{% if form.vars['errors'] is not empty %}
Magic errors display!
{% endif %}
<?php
use Symfony\Component\DependencyInjection\ContainerBuilder;
$container = new ContainerBuilder();
// ... set up the container
// might be helpful to check if the service is synthetic
var_dump($container->getDefinition('my.synthetic.service')->isSynthetic()); // true
<?php $i=0; foreach($result as $rt_val) { if(!$i) echo $rt_val['name']; $i++; }
<?php
$i = 0;
foreach ($result as $rt_val) {
if (!$i) {
echo $rt_val['name'];
}
$i++;
<?php
function getName(array $result)
{
// resets the array pointer
// possibly be bad
// but let's say it isn't in this case
$firstEntry = reset($result);
if (is_array($firstEntry) && isset($firstEntry['name'])) {