Symfony2: get controller / action name in Twig template

5

Category : PHP, Symfony2

In one of my templates i needed a simple way to get controller / action name to generate some dynamic urls. Symfony2 does not offer any Twig helper function to display current controller / action name.

The easiest way that i have found so far is to create Twig extension. In our default bundle we need to create folder Twig/Extension for example Acme/PageBundle/Twig/Extension and place there our Twig extension class: → Continue

Symfony2 – pierwsze wrażenia

4

Category : PHP, Symfony2

Od jakiegoś czasu starałem się znaleźć odpowiedni moment / trochę wolnego czasu na zapoznanie się z najnowszą wersją frameworka Symfony. Jako, że wiele osób zastanawia się / rozważa migrację swoich dotychczasowych projektów, bądź też rozpoczęcie nowych na Symfony2 postanowiłem przedstawić moje subiektywne obiektywne zdanie na temat możliwości Symfony2.
→ Continue

Symfony 1.4 – sfImageFileValidator – validate image dimensions

1

Category : PHP, Symfony

Default symfony 1.4 file validator can validate only some basic file attributes. Sometimes we need more, for example we want to prevent small images from being uploaded. Code below presents my custom sfImageFileValidator which allows you to apply some dimensions constraints to image file validation, e.g. max_height or max_width.

→ Continue

Krótko o książce: „Symfony w przykładach”

9

Category : PHP, Symfony

W odpowiedzi na liczne pytania, poniżej chciałbym w kilku zdaniach przedstawić moją subiektywną opinię na temat najnowszej Polskiej książki dotyczącej Symfony Framework. Prezentowana książka wg rankingów Helion, jest obecnie jedną z najlepiej sprzedających się pozycji – numer 2 na liście bestsellerów.
Na samym początku chciałbym zaznaczyć, że z dość dużym dystansem podchodzę do tego typu pozycji – książki i materiały udostępniane na stronie projektu powinny w zupełności wystarczyć na początku przygody z Symfony.
→ Continue

Zend framework – Zend_Validate_Db_Unique draft

1

Category : PHP, Zend Framework

Zend framework has a lot of o really nice features. Lately i had an opportunity to work with Zend_Form (also with its validation system) and Zend_Db (my most hated component of ZF). Playing with DB i needed a simple way to check if new item (record) is unique. Unfortunately i haven’t found Zend_Validate_Db_Unique component :) There is Zend_Validate_Db_NoRecordExists/RecordExists but it only checks if record exists/not exists in db. The code below is my proposal for new validation component:


/**
 * @see Zend_Validate_Db_Abstract
 */
require_once 'Zend/Validate/Db/Abstract.php';

/**
 * Confirms a record is unique in a table.
 *
 * @uses       Zend_Validate_Db_Abstract
 */
class Zend_Validate_Db_Unique extends Zend_Validate_Db_Abstract
{
    /**
     * @var Zend_DB_Table_Row
     */
    protected $_row = null;

	public function __construct($table, $field, Zend_DB_Table_Row $row, Zend_Db_Adapter_Abstract $adapter = null)
    {
        parent::__construct($table, $field, null, $adapter);

        $this->_row   = $row;

        $this->setMessage("A record matching %value% already exists.", self::ERROR_RECORD_FOUND);
    }  

    public function isValid($value)
    {
        $valid = true;
        $this->_setValue($value);

		$result = $this->_query($value);

		if (!$result || $this->isUpdate()) {

			return true;
		}

		$this->_error(self::ERROR_RECORD_FOUND);

        return false;
    }

  protected function isUpdate()
  {
      if (!isset($this->_row[$this->_field]) || $this->_row[$this->_field] != $this->_value)
      {
        return false;
      }

    return true;
  }
}

→ Continue

Symfony 1.4 and SSL – playing with symfony filters

8

Category : PHP, Symfony

Building last application i needed SSL protection for some of my modules and actions. What I wanted to achieve was to choose some actions and redirect non-https requests to https (and https to non-https).
I found a plugin: sfSslRequirementPlugin, it’s for sf 1.0/1.1 and it does not really meet my needs. Yes, i know that i can fix it to work with sf 1.4 but that’s not a point.

Then in the documentation i found simple ssl filter example:

< ?php

class sfSecureFilter extends sfFilter
{
  public function execute($filterChain)
  {
    $context = $this->getContext();
    $request = $context->getRequest();

    if (!$request->isSecure())
    {
      $secure_url = str_replace('http', 'https', $request->getUri());

      return $context->getController()->redirect($secure_url);
      // We don't continue the filter chain
    }
    else
    {
      // The request is already secure, so we can continue
      $filterChain->execute();
    }
  }
}

→ Continue

Symfony – how to set up default database encoding?

3

Category : PHP, Symfony, Zend Framework

Maybe it’s nothing special and difficult but i remember the day (some time go) when i had a problem with setting up default database encoding in my application. I recently received some questions about it so i decided to post this here and help some of you.

→ Continue

Advanced data filtering with Symfony 1.4 and ExtJS 3.2 [english]

10

Category : Ext JS, JavaScript, PHP, Symfony

After a couple of weeks I finally found some time to write about Symfony and ExtJS. This time i want to show how to put together to work Symfony 1.4, ExtJS 3.2 and Grid Filter Plugin – for me it’s the one of most powerfull filtering solutions i have ever seen.
Since my last entry about displaying data in ExtJS Grid Panel i have updated Ext library to 3.2 version – they have added some nice features (more information you can find in changelog 3.1 and changelog 3.2) and changed some ExtJs components (more details you will find later).

→ Continue

Symfony and jQuery: sfWidgetFormJQueryMultiSelect ver 0.1

20

Category : Ext JS, JavaScript, jQuery, News, PHP, Symfony

Recently i created nice and simple Symfony widget: sfWidgetFormJQueryMultiSelect. It’s really simple in use and implementation. I have used code written recently by Eric Hynds: jQuery MultiSelect Plugin w/ ThemeRoller Support and standard sfWidgetFormChoice.

→ Continue

ExtJS and simple JavaScirpt Internationalization (i18n)

4

Category : Ext JS, JavaScript

Lastely, building quite big Symfony and Ext.js application i was looking for simple way to make my application internationalized. I haven’t found any good solutions that would suits my needs. I found this on extjs forum: ‘The simplest way, perhaps, is to extract hardcoded strings to locale files. Then your framework just have to load the selected language file together with YUI-ext.” I didn’t like that idea, i think it would be good for building some custom components but not for internationalize the whole application. I needed something quicker and less complicated.
Than, i thought that i can write my own simple i18n mechanism – maybe there is better way (files can be generated on the server side), but this work for sure.
→ Continue