Tag-Archive for ◊ Symfony ◊

Author:
Thursday, March 24th, 2011

In symfony framework, we can generate WSDL files easily by using ckwebservice plugin.
There are different releases available in this plugin. We need to choose the release which suits for our symfony version.
To install this plugin type the following command

php symfony plugin:install ckWebServicePlugin

To use this plugin, we need to make changes in our application’s configuration files also.

1. In app.yml
all:
enable_soap_parameter: off
soap:
# enable the `ckSoapParameterFilter`
enable_soap_parameter: on
ck_web_service_plugin:
# the location of your wsdl file, relative to your project's `web/` folder
wsdl: %SF_WEB_DIR%/Billing.wsdl
# the class which will be registered as handler for webservice requests
handler: BillingHandler
soap_options:
encoding: utf-8
soap_version: <?php echoln(SOAP_1_2) ?>
classmap:
# mapping of wsdl types to PHP types
DoubleArray: ckGenericArray

Note : Billing.wsdl and BillingHandler is our WSDL and Handler names respectively.

2. In factories.yml
# your environment for webservice mode
soap:
controller:
class: ckWebServiceController

3. In filters.yml (only Symfony 1.3 or later versions)

rendering: ~
security:  ~
# insert your own filters here
cache:     ~
common:    ~
execution: ~
soap_parameter:
class: ckSoapParameterFilter
param:
# `app_enable_soap_parameter` has to be set to `on` so the filter is only enabled in soap mode
condition: %APP_ENABLE_SOAP_PARAMETER%

In symfony 1.2 or less versions filters.yml should look like this:

rendering: ~
security:  ~
# insert your own filters here
soap_parameter:
class: ckSoapParameterFilter
param:
# `app_enable_soap_parameter` has to be set to `on` so the filter is only enabled in soap mode
condition: %APP_ENABLE_SOAP_PARAMETER%
cache:     ~
common:    ~
execution: ~

Now we are ready to use this plugin. Once our action file is ready we can generate WSDL file by using ‘webservice:generate-wsdl’ command. Syntax of this command is

php symfony webservice:generate-wsdl [--environment=soap] [--debug] [--handler] app_name webservice_name  webservice_base_url

  • [--environment=soap] – (Optional) This sets the environment to webservice mode. Default value is ‘soap’
  • [--debug]  – (Optional) This enables the debug mode. Default is ‘FALSE’
  • [--handler] – (Optional) This generates custom SOAP handler by extending ckSoapHandler. Default is ‘FALSE’
  • app_name – Name of the application
  • webservice_name – Name of the webservice
  • webservice_base_url – URL under which webservice is accessable

For example :
php symfony webservice:generate-wsdl frontend Billing http://localhost:8080/

The above command will generate Billling.wsdl and BillingHandler.php in ‘web/’ folder
To view the generated WSDL file : http://localhost:8080/Billing.wsdl

Author:
Tuesday, February 23rd, 2010

Steps for setting up error reporting in Symfony

You can set up the Error Reporting Level, in myapp/config/settings.yml

prod:

.settings:

error_reporting:  257

dev:

.settings:

error_reporting:  4095

4095 is a shortcut for E_ALL | E_STRICT

257 stands for E_ERROR | E_USER_ERROR (the default value for every new environment)

Symfony can log a lot of custom events. You can find all the symfony logs under the myproject/log/ directory

There are eight levels of symfony log messages: emerg, alert, crit, err, warning, notice, info, and debug. You can configure the maximum level to be logged in each environment in the logging.yml

Default Logging Configuration, in myapp/config/logging.yml

prod:
  enabled: off
  level:   err
  rotate:  on
  purge:   off
 dev:
 test:
 #all:
#  enabled:  on
#  level:    debug
#  rotate:   off
#  period:   7
#  history:  10
#  purge:    on

You can manually add a message in the symfony log file from your code by using one of the techniques described below

// From an action
$this->logMessage($message, $level);
// From a template
<?php use_helper('Debug') ?>
<?php log_message($message, $level) ?>

For clearing the log use the below command.

symfony log-purge
Category: PHP, Symfony | Tags: , ,  | One Comment
Author:
Friday, January 29th, 2010

While working on symfony framework we faced some issues and in this blog I am going to discuss about the issues and fixes for that issues.

Problem 1 :

symfony 1.2 propel-build-model Bus error

(Crashes PHP CLI when we try to execute

symfony propel-build-model or

symfony propel-build-all

)
Solution :

Execute €˜symfony propel-build-model’ ends with ‘Bus error’

I found this is caused by one field type in db with default value:

I have a column called €˜created_at’of type: timestamp with default value ‘CURRENT_TIMESTAMP’, this is on MYSQL level.

Execute €˜propel-build-schema’ at symfony command line

you will get

created_at: { type: TIMESTAMP, required: true, defaultValue: CURRENT_TIMESTAMP } then, run ‘propel-build-model’, you would get ‘Bus error’

propel generator might not know ‘CURRENT_TIMESTAMP’. After removing this from scheme.yml, you can run that script smoothly.

Problem 2 :

When we tried to host the symfony project which we developed to Linux server, it displayed blank page.

Solution :

It’s because of the case sensitivity of filenames.

Ex: we have a file Test.php, in windows if we include test.php it will work but in Linux it will fail because of case sensitivity.

Author:
Saturday, January 09th, 2010
MVC is not a new concept. It is considered by some to the evolution of IPO (Input, Processing, Output), which was the best-practice model applied to the linear, text-only applications. Since PHP is simple and not type specific, it can be easily abused to the point at which applications become unmaintainable. This is mainly because of combining model, vie and controller into a single PHP script. In a proper MVC application, there are no scripts, only components.
How Not to Do It
Ask any inexperienced PHP developer to create a small login or guestbook application and he/ she will probably come up with a single file. The file would be called login.php or guestbook.php and would handle both displaying, adding, validations etc. This approach has number of problems, quite apart from using GET instead of  POST to effect a change in a database.
Instead, take a look at a more mature approach to development that allows you to follow the MVC design.
An MVC Approach
The first rule of MVC in PHP is to split up your files. There are number of possible approaches, but many favor taking the step of actually using different file extensions to represent different roles in the MVC pattern and then using require_once at the appropriate time to link together.
If you are unsure as to what code should appear in which modules, you can rely on a few rules to ensure that you’re following this methodology:
.php (control page) should never contain SQL queries or HTML.
.phpm (classes) should never contain HTML
.phtml (templates) should never contain SQL quries, and only very basic PHP (for/if/while).
MVC in Symfony Framework
If you are used to developing PHP websites without a framework, you probably use the one PHP file per HTML page paradigm. These PHP files probably contain the same kind of structure: initialization and global configuration, business logic related to the requested page, database records fetching, and finally HTML code that builds the page.
You may use a templating engine to separate the logic from the HTML. Perhaps you use a database abstraction layer to separate model interaction from business logic. But most of the time, you end up with a lot of code that is a nightmare to maintain. It was fast to build, but over time, it’s more and more difficult to make changes, especially because nobody except you understands how it is built and how it works.
As with every problem, there are nice solutions. For web development, the most common solution for organizing your code nowadays is the MVC design pattern. In short, the MVC design pattern defines a way to organize your code according to its nature. This pattern separates the code into three layers:
The Model layer defines the business logic (the database belongs to this layer). You already know that symfony stores all the classes and files related to the Model in the lib/model/ directory.
The View is what the user interacts with (a template engine is part of this layer). In symfony, the View layer is mainly made of PHP templates. They are stored in various templates/ directories.
The Controller is a piece of code that calls the Model to get some data that it passes to the View for rendering to the client. When we installed symfony the first day, we saw that all requests are managed by front controllers (index.php and frontend_dev.php). These front controllers delegate the real work to actions.
Developers, try to implement your code in MVC structure even though its small application, to make your code clean and manageable. PHP is a great and simple language, but as a developer we need to make our code with all the major standards, security stuffs with good architecture to make our PHP language proud and also it gives more satisfaction to us.
Enjoy Good Coding :)

MVC is not a new concept. It is considered by some to the evolution of IPO (Input, Processing, Output), which was the best-practice model applied to the linear, text-only applications. Since PHP is simple and not type specific, it can be easily abused to the point at which applications become unmaintainable. This is mainly because of combining model, vie and controller into a single PHP script. In a proper MVC application, there are no scripts, only components.

How Not to Do It

Ask any inexperienced PHP developer to create a small login or guestbook application and he/ she will probably come up with a single file. The file would be called login.php or guestbook.php and would handle both displaying, adding, validations etc. This approach has number of problems, quite apart from using GET instead of  POST to effect a change in a database.

Instead, take a look at a more mature approach to development that allows you to follow the MVC design.

An MVC Approach

The first rule of MVC in PHP is to split up your files. There are number of possible approaches, but many favor taking the step of actually using different file extensions to represent different roles in the MVC pattern and then using require_once at the appropriate time to link together.

If you are unsure as to what code should appear in which modules, you can rely on a few rules to ensure that you’re following this methodology:

i.    .php (control page) should never contain SQL queries or HTML.

ii.   .phpm (classes) should never contain HTML

iii.  .phtml (templates) should never contain SQL quries, and only very basic PHP (for/if/while).

MVC in Symfony Framework

mvc

If you are used to developing PHP websites without a framework, you probably use the one PHP file per HTML page paradigm. These PHP files probably contain the same kind of structure: initialization and global configuration, business logic related to the requested page, database records fetching, and finally HTML code that builds the page.

You may use a templating engine to separate the logic from the HTML. Perhaps you use a database abstraction layer to separate model interaction from business logic. But most of the time, you end up with a lot of code that is a nightmare to maintain. It was fast to build, but over time, it’s more and more difficult to make changes, especially because nobody except you understands how it is built and how it works.

As with every problem, there are nice solutions. For web development, the most common solution for organizing your code nowadays is the MVC design pattern. In short, the MVC design pattern defines a way to organize your code according to its nature. This pattern separates the code into three layers:

The Model layer defines the business logic (the database belongs to this layer). You already know that symfony stores all the classes and files related to the Model in the lib/model/ directory.

The View is what the user interacts with (a template engine is part of this layer). In symfony, the View layer is mainly made of PHP templates. They are stored in various templates/ directories.

The Controller is a piece of code that calls the Model to get some data that it passes to the View for rendering to the client. When we installed symfony the first day, we saw that all requests are managed by front controllers (index.php and frontend_dev.php). These front controllers delegate the real work to actions.

Developers, try to implement your code in MVC structure even though its small application, to make your code clean and manageable. PHP is a great and simple language, but as a developer we need to make our code with all the major standards, security stuffs with good architecture to make our PHP language proud and also it gives more satisfaction to us.

Enjoy Good Coding :)

Author:
Monday, December 14th, 2009

What’s Symfony?
Symfony is a web application MVC framework for PHP projects. It aims to speed up the creation and maintenance of web applications, and to replace the repetitive coding tasks.

Why use an MVC framework?

  • Avoid €œreinventing the wheel€
  • Use proven, tested code
  • Speed up application development
  • Easy to maintain
  • Code cleanliness
  • Structured the code

Why Symfony?

  • Supports complex web applications
  • Idea adopted from existing framework (Mojavi, Prado, rails, Django)
  • Clean MVC Seperation
  • Configurability, Flexibility
  • Write less code
  • Support Unit testing and functional testing

Database Support

  • Mysql, PostgreSQL, Oracle
  • Object Role Modeling (ORM)
  • Propel as default
  • It doesn’t require extrenal ORM

The Symfony supports most of the databases and the beauty of framework is that we can change the database at any stage of development. Since the database is different layer it won’t affect the other layer of the code.

Speed & Performance

  • Cache configuration
  • Caching on page, function , query
  • Disable / enable plugins, databases, modules

Other Features

  • Easy to Manage Template
  • SEO Friendly link/ url
  • Friendly logging
  • Assessment on loading time

Plugins and helper

  • Ajax enabled plugins
  • jQuery, dojo, extjs, yui
  • Create your own plugin and reuse
  • Autocomplete
  • Drag and drop
Famous Applications
Yahoo! answer
Yahoo! bookmark
delcious
Daily Motion
etc…

Famous Applications using Symfony Framework

Yahoo! answer

Yahoo! bookmark

delcious

Daily Motion

etc…