Tag Archive for 'PHP'

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’

Zend Framework + Doctrine + jQuery Grid

Today i will show you how to put together: Zend Framework, Doctrine and simple jQuery Grid in easy way. All i want to do is to get some data from database with doctrine, format that data and send it to the template with Zend_Json:) Really nothing special.

Ok. Let’s start. First of all we need to create database schema.yml. It is realy easy country table:


Country:
  tableName: country
  columns:
    id:
      primary: true
      autoincrement: true
      type: integer(10)
    name: string(50)
    description: string(255)

Continue reading ‘Zend Framework + Doctrine + jQuery Grid’

Zend Framework + Doctrine - introduction

Some time ago i have shown you how to integrete Doctrine with our Zend Framework. Because it is really hard to say how much i hate the Zend_Db_Table ideology of working with database (i think it is not only my opinion), i will try to show you advantages of the Doctrine way. In this post I only want to give you some really easy introduction to Doctrine with Zend (it is just introduction without real world examples).

Doctrine

is an object relational mapper (ORM) for PHP 5.2.3 and later that sits on top of a powerful database abstraction layer (DBAL). One of its key features is the option to write database queries in a proprietary object oriented SQL dialect called Doctrine Query Language (DQL), inspired by Hibernates HQL. This provides developers with a powerful alternative to SQL that maintains flexibility without requiring unnecessary code duplication.
Continue reading ‘Zend Framework + Doctrine - introduction’

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′

Symfony 1.1 - editing uploaded file with sfForm

Lately, i a had problem with editing uploaded file.
I had an object with field “photo” that was linking to the uploaded image.
When I was editing the object and leaving the input file blank (not selecting any other image) the form saved NULL in database.

I was looking for solution on many forums and in documentation but i didn’t found anything that could help me.
Finally, i solved the problem (maybe it’s not the best way, but it’s working really good).
Continue reading ‘Symfony 1.1 - editing uploaded file with sfForm’




About me:

  • PHP programmer
  • Symfony developer
  • Zend framework developer

Categories: