Tag Archive for 'symfony'

Symfony 1.2 and multipage form - wizard

This time i want to give you simple example about how to create multipage (wiazard) form using great Symfony 1.2 form framework. It would be simple 3 steps registeration form with validation after each step. In this example i’m using propel but it would also work great wiht Doctrine. Lets start!

First, we need to start a new project, create frontend application and multiPageForm module (from the command line prompt):

symfony generate:project multipageFormApp

symfony generate:app frontend

symfony generate:module frontend multiPageForm

Continue reading ‘Symfony 1.2 and multipage form - wizard’

Symfony i Zend Framework

Celowo nie chciaÅ‚em tytuÅ‚ować wpisu Symfony vs Zend Framework bo wpisów o podobnej tematyce jest bardzo dużo. Jedne mniej, drugie bardziej konkretne i sensowne. Można siÄ™ spierać który z tych dwóch frameworków jest lepszy, jednak tak naprawdÄ™ pytanie brzmi, który jest dla nas bardziej odpowiedni, intuicyjny i z którym bÄ™dzie Nam siÄ™ lepiej pracowaÅ‚o. Ogólnie rzecz biorÄ…c bardzo drażniÄ…cÄ… sprawÄ… sÄ… wszelkie kłótnie: “który framework lepszy?”, “który wybrać”, “Zend Framework vs Symfony” - wszystko zależy od wymagaÅ„ projektu i programisty. Porównanie tym bardziej jest trudne, że Zf i Sf z zaÅ‚ożeÅ„ oferujÄ…c podobne możliwoÅ›ci, sÄ… zupeÅ‚nie różne. PostanowiÅ‚em wiÄ™c przedstawić moje skromne zdanie.

Z góry zaznaczam, że nie będę tutaj pisał nic o Cake PHP, CodeIgniter czy Kohanie. Nigdy nie miałem okazji pracować z żadnym z tych frameworków i w najbliższym czasie nie przewiduje, żeby coś w tym temacie się zmieniło.

Poniżej postaram się krótko i konkretnie przedstawić moje osobiste przemyślenia na ten temat, na podstawie własnych doświadczeń jakie mam w pracy z Sf i ZF. Wszelkie uwagi i opinie są bardzo mile widziane.
Continue reading ‘Symfony i Zend Framework’

Symfony 1.2 - tasks and cron

I was wondering if there is any simple way in Symfony for calling cron job. I found in the documentation that we can use Batch files - it is kind of PHP script that looks similar to symfony front controller, all we need to do is to initalize symfony, parse project and application Configuration. Quite cool but there is better way (just in my opinion) to access all symfony features from the command line: tasks.
Every time we are creating project, generating modules, building models/forms we use standard symfony tasks. Task are grouped by namespace and name - this allows us to build intuitive script names. For example namespace: propel or doctrine, and the task name: build-model, build-sql. Why we should use tasks instead of batch files? Tasks are really simple, powerful and they take care of parsing command line arguments and options, initalizing needed configuration and classes. To create a simple task we have to create a class that exetend sfBaseTask and put it into lib/task/ directory. File name must ends with “Task.class.php” to be properly loaded.
Another great thing about tasks is that Symfony also provide task for generating new, custom tasks :)
Continue reading ‘Symfony 1.2 - tasks and cron’

Symfony + jQuery Flexigrid

Nothing special but some of you had problems putting it together. So, i decided to write simple tutorial describing how to use jquery Flexigrid with Symfony. I will use the same data as in the tutorial: Zend Framework + Doctrine + jQuery Grid . Eveything will be the same, except that we will use Symfony instead of Zend.

First we need to create new symfony project:

symfony generate:project someProjectName

or simply download sf_sandbox.

Next step is to create symfony app:

symfony generate:app frontend

Then we need one module, for example “grid”:

symfony generate:module frontend grid

Continue reading ‘Symfony + jQuery Flexigrid’

Małe aplikacje - jaki framework?

W odpowiedzi na liczne pytania, chciałbym krótko przedstawić moją opinie na temat plusów i minusów korzystania z frameworków w małych aplikacjach i czy warto w ogóle z nich korzystać.

Moja odpowiedź to stanowcze TAK. Jest bardzo dużo plusów i raczej znikoma ilość minusów (w tym momencie, żadne nie przychodzą mi do głowy). Oczywiście podstawa to poznać framework nim zaczniemy jakąkolwiek pracę - obsługę żądań, przepływ danych, nazewnictwo metod/akcji/kontorlerów, warstwę abstrakcji dla bazy danych i widoki.

Trudno mówić tutaj o wyborze najlepszego rozwiązania, każdy framework ma swoje wady i zalety. Ja szczerze polecam Syfmony i Zend Framework - niestety nie miałem jeszcze wystarczająco dużo czasu by móc poznać cakephp czy code ingniter, z drugiej jednak strony te których używam w zupełności mi wystarczają i jak do tej poty nie musiałem szukać innych rozwiązań.
Continue reading ‘MaÅ‚e aplikacje - jaki framework?’

Symfony 1.2 - sfForm - Yet another useful function - part 2

A couple of weeks ago i have shown you really useful example about unsetting sfForm fields - unsetAllExcept. Since that i was palying with sfForm and i found more functions that could help you working with symfony forms.

All methods shown below have to be added to BasePropelForm class (or Doctrine depending on ORM we use).

Setting single form value
There is no really simple way to set single value of field - i’m not talking about setting default value. We can call getValue on Form but not setValue. Imagine situation when we post a form and just after binding we want to set value. You can find exampe in this post.


<?php

   /**
   * Sets a value for a form field.
   *
   * @param string $field	The field name
   * @param mixed  $value	The default value
   */
    public function setValue($field, $value){

    	if(!in_array($field, array_keys($this->values))){

    		throw new sfException(sprintf('Unkown field" "%s" in "%s" object.', $field, get_class($this)));
    	}

    	$this->values[$field] = $value;
    }

?>

Continue reading ‘Symfony 1.2 - sfForm - Yet another useful function - part 2′

Symfony 1.2 - using sfForm with jquery validate plugin

Build-in symfony form validation is really great feature. Using Propel or Doctrine ORM we have simple validation by default which we can modify in simple way.
But sometimes we want something more than server side validation (later in post SSV) and then we can easliy use javascript. Client side validation (CSV) is nice and useful but we need to remember that it could be easily switched off. So SSV is always required.

Let’s begin.

I’m not going to build a whole application. I just want to show you how to create simple contact form, validate it using SSV and CSV (with jQuery) and save it.

First of all we need to create new symfony app. If we have symfony already installed on our PC, we can just create new project directory, for example sfSimpleApp and then call:


<?php

    symfomy generate:project sfSimpleApp

?>

Remember that you need to write symfony tasks in command line (on windows -cmd prompt).
As it is a simple example we are not going to configure a web server.

Continue reading ‘Symfony 1.2 - using sfForm with jquery validate plugin’

Zend Framework + Smarty + FlashMessenger helper

Today i was looking for solution similiar to symfony: setFlash() message. I found in Zend documentation that there is something like FlashMessenger helper. There was even some useful example, so i decided to put it all together and show you how to use that helper with our Zend Framework Structure.

For those who don’t know what are flash messages for, i will give simple example.
Imagine situation that you are adding new item. You are processing form, saving data and redirecting to main/list page. But what about user-friendly message telling that item was successfully saved? We can set some parameters and then check their values but there is better way - flash message. We can easily do something like setFlashMessage and redirect user to other page. Then all we need to do is to check in our template if any flash message is set and put in on display.

Continue reading ‘Zend Framework + Smarty + FlashMessenger helper’

Symfony 1.2 - sfForm - Yet another useful function

Working on my new project i really need to find a good solutions for unsetting many fields in easy way. I don’t really like philosophy of unsetting each element that i don’t need. Sometimes when i add new fields to my tables i must remember to unset (all) that fields in my Forms - really irritating:) Finally i found a solution which is working really good for me - it’s nothing special but really helpfull.
Continue reading ‘Symfony 1.2 - sfForm - Yet another useful function’

Symfony 1.2

Już praktycznie od tygodnia dostępna jest nowa wersja świetnego (przynajmniej w mojej opinii) frameworka dla PHP. Nie będę tutaj wychwalał wszystkich zalet tego frameworka - po szczegóły odsyłam na stronę projektu Symfony , wymienię jednak kilka najbardziej istotnych zmian:
-w wersji 1.1 mogliśmy przetestować nowy, w pełni obiektowy framework dla formularzy, w 1.2 został on poprawiony i ulepszony (zagnieżdżone formularze są teraz naprawdę zagnieżdżone, wywołanie metody save na formularzu wywołuje save na podformularzach, nowe widgety m.in. sfWidgetFormChoice i walidatory);
Continue reading ‘Symfony 1.2′




About me:

  • PHP programmer
  • Symfony developer
  • Zend framework developer

Categories: