Niezalogowany [ logowanie ]
Subskrybuj kanał ATOM Kanał ATOM    Subskrybuj kanał ATOM dla tagu symfony2 Kanał ATOM (tag: symfony2)

Autor wpisu: Kamil Adryjanek, dodany: 15.03.2013 08:30, tagi: symfony2, php, symfony

We wtorek 19 marca 2013 o 16:15 na Politechnice Lubelskiej, będę miał przyjemność poprowadzić wykład w ramach projektu: „Zdobądź wiedzę z Performance Media”. Tematem viagra price

mojego wykładu będzie: „Ewolucja projektowania aplikacji w PHP na bazie frameworka Symfony2″.

Poniżej znajduje się krótka agenda:

  • Ewolucja PHP. Krótka historia, ekosystem, co nowego w PHP?
  • Dlaczego Symfony2? Przegląd najważniejszych i najciekawszych możliwości frameworka;
  • Symfony2 w praktyce. Mini przegląd popularnych Bundli + CMS w 5 minut.

Wszystkich zainteresowanych tematem PHP / Symfony2 serdecznie zapraszam!

Więcej informacji na temat samych wykładów można znaleźć na stronie: Wykłady Performance Media

Autor wpisu: Kamil Adryjanek, dodany: 06.03.2013 02:23, tagi: symfony2, php, symfony

Symfony2 comes with a very nice validation system and allows us for example to add a constraint to any public method whose cheap viagra name starts with „get” or „is” („Getters”) and not only. In combination with the Validation Groups it is a really powerfull tool. This time i want to show you how to map those errors.

Adding custom method to entity we can add some extra validations for example to address field:

<?php
// some entity class
/**
 * Checks if user provides a valid address
 *
 *  @Assert\True(message = "user.address.invalid")
 */
public function isAddressValid()
{
    // some logic
}

Now this entity will be also checked against extra rules form isAddressValid method. That’s really cool and easy but there was one thing that forced me to choose Callback Validation and its:

$context->addViolationAt('address', 'user.address.invalid', array(), null);

instead of Getters in many cases: i was not allowed to assign errors to specific fields on my object. It means that i couldn’t make these errors display next to a specific field and they were displayed at the top of my form – since Symfony2.1 it’s not a problem any more.

Thank to new error mapping funcionality: „error_mapping” we can now set which method should be mapped to a given field”:

<?php
class UserType extends AbstractType
{
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'error_mapping' => array(
                // this line tells Symfony to assign Getter Constraint to address property
                'addressValid' => 'address'
             ),
        ));
    }
}

Since error_mapping is set, errors will be displayed next to address filed.

We can also use dot for building nested property paths and assign errors to embedded forms:  ‚cityValid’ => ‚address.city’ or ‚address.cityValid’ => ‚city’ – depending on our needs.

Ecard Wizard Greeting Card Software zp8497586rq

Autor wpisu: Tomasz Kowalczyk, dodany: 25.01.2013 11:04, tagi: php, doctrine, mysql, symfony, symfony2

Jakiś czas temu chciałem poeksperymentować trochę z bazą danych jednego z projektów FLOSS w Symfony2.         Importując dane z MySQLa poprzez komendę zostałem przywitany przez Doctrine2 wyjątkiem: [Doctrine\DBAL\DBALException] Unknown database type enum requested, Doctrine\DBAL\Platforms\MySqlPlatform may not support … #LINK#

Autor wpisu: Wojciech Sznapka, dodany: 04.11.2012 22:52, tagi: php, symfony, symfony2

Is Symfony2 a MVC framework? This question in tricky and you can't see answer at the first moment when you visit symfony.com website. Even more - MVC pattern isn't mentioned in elevator pitches in "What is Symfony" section. Most of PHP developers will tell you promptly, that this is Model View Controller implementation without a doubt. The question is: where is Model layer in Symfony2? My answer is: there's ain't one and it's good..

Autor wpisu: Kamil Adryjanek, dodany: 20.10.2012 13:27, tagi: symfony2, php

Today i would like to share my recent experience on forms and data dependent fields. Playing with Symfony2 forms some time ago i was looking for best solutions of adding fields to forms that depend on the data / Doctrine object – there was nothing about it in the official Symfony documentation. I thought, as many other developers that the best / easiest way is to pass the current object in form constuctor. Today i know it was wrong but what is the recommended solution? Is there any easy way to add / remove form fields?

Imagine a scenario:

Implementing form in the old way i will write code:

<?php

namespace My\AdminBundle\Form;

use My\AdminBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
    protected $user = null;

    public function __construct(User $user)
    {
      $this->user = $user;
    }

    public function buildForm(FormBuilderInterface $builder, array $options)
    {
      $builder
        ->add('firstName', 'text', array('label' => 'First name'))
        ->add('lastName', 'text', array('label' => 'Last name'))
        ->add('email', 'email', array('label' => 'Email address'))
        ;
      // add permissions for none admin users
      if (!$this->user->isAdmin()) {
        $builder
          ->add('permissions', 'entity', array(
        'label'   => 'Access Permisson',
        'class'   => 'AdminBundle:Permission',
        'multiple'  => true,
        'expanded'  => true
      ))
      }
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'My\AdminBundle\Entity\User'
        ));
    }

    public function getName()
    {
        return 'my_adminbundle_usertype';
    }
}

But according to Bernhard Schussek the recommended way of playing with dependent fields in Symfony forms is to add / remove fields using EventListeneres on form events. Using FormEvent we can access our data object ($event->getData()), current form ($event->getForm()) and determine which fields add or remove accoridng to User object.

Yes, it may seem a bit complicated but i will try to show it in UserType example:

<?php

namespace My\AdminBundle\Form;

use My\AdminBundle\Entity\User;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
      $builder
        ->add('firstName', 'text', array('label' => 'First name'))
        ->add('lastName', 'text', array('label' => 'Last name'))
        ->add('email', 'email', array('label' => 'Email address'))
        ;
      $formFactory = $builder->getFormFactory();
      // add permissions for none admin users
      $builder->addEventListener(FormEvents::PRE_SET_DATA,
        function (FormEvent $event) use ($formFactory) {
          if (!$event-&gt;getData()->isAdmin()) {
            $event->getForm()->add($formFactory->createNamed(
              'permissions', 'entity', null, array(
                'label'   => 'Access Permisson',
                'class'   => 'AdminBundle:Permission&quot',
                'multiple'  => true,
                'expanded'  => true
            )));
          }
        }
      );
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'My\AdminBundle\Entity\User'
        ));
    }

    public function getName()
    {
        return 'my_adminbundle_usertype';
    }
}

Maybe it’s better, maybe it’s recommended way of adding dependent fields but in my opinion it also quite complicated. What about forms where we have many dependent fields? It’s a lot of code just for one filed. It really needs simplification. list of online casinos

Autor wpisu: Kamil Adryjanek, dodany: 11.10.2012 13:27, tagi: symfony2, php

Composer is a amazing tool for dependency managment in PHP. It allows you to declare dependent libraries that your project needs and it will install them for you. You can find more information on official composer website.

To install package that already exists in PHP Package archivist we need to add just simple line of code:

File composer.json (in this example to install Doctrine extensions):

<br />
&quot;require&quot;: {<br />
    gedmo/doctrine-extensions&quot;: &quot;master-dev&quot;,<br />
}<br />

But what about libraries that are not composer aware? Still many bundles don't have composer.json. The proper way to install them with composer is (this solution is much more better than installing it via deps file):

In composer.json file we need to add repositores section:

<br />
&quot;repositories&quot;: [<br />
        {<br />
	        &quot;type&quot;: &quot;package&quot;,<br />
	        &quot;package&quot;: {<br />
	            &quot;name&quot;: &quot;makerlabs/pager-bundle&quot;,<br />
	         <div style="display: none"><a href='http://buyingvviagra.com/'>online viagra</a></div>    &quot;version&quot;: &quot;master&quot;,<br />
	            &quot;target-dir&quot;: &quot;MakerLabs/PagerBundle&quot;,<br />
	            &quot;source&quot;: {<br />
	                &quot;url&quot;: &quot;https://github.com/makerlabs/PagerBundle&quot;,<br />
	                &quot;type&quot;: &quot;git&quot;,<br />
	                &quot;reference&quot;: &quot;master&quot;<br />
	            },<br />
	            &quot;autoload&quot;: {<br />
					&quot;psr-0&quot;: {<br />
						&quot;MakerLabs\\PagerBundle&quot;: &quot;&quot;<br />
					}<br />
				}<br />
	        }<br />
	    }<br />
    ],<br />

And then just:

<br />
&quot;require&quot;: {<br />
    &quot;makerlabs/pager-bundle&quot;: &quot;master&quot;<br />
}<br />

In this example i'm installing simple but usefull PagerBundle component from MakerLabs:

Czytaj dalej tutaj (rozwija treść wpisu)
Czytaj dalej na blogu autora...

Autor wpisu: Tomasz Kowalczyk, dodany: 30.08.2012 02:18, tagi: symfony2

Ten wpis to bardziej przypominacz na przyszłość, ale dosyć przydatny, ponieważ korzystam z Symfony2 już prawie / ponad rok i podczas stawiania kolejnych serwerów / VPSów ciągle „łapię się” na ten haczyk z niezainstalowanym pluginem do SQLite w stosie LAMP. … #LINK#
Wszystkie wpisy należą do ich twórców. PHP.pl nie ponosi odpowiedzialności za treść wpisów.