Monthly Archive for styczeń, 2009

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’




About me:

  • PHP programmer
  • Symfony developer
  • Zend framework developer

Categories: