New sfAmfPlugin release

Posted by thaberkern on Jun 29 2009 | General

I have just released a new version of my Symfony-Plugin sfAmfPlugin. The new version 1.4.0 has the following changes included:

  • Added an error handler function. All Errors will now be delivered as an exception (thanks to raphox for this)
  • Fixing problem with associative array values
  • Updated SabreAmf to version 1.3.0
  • Added correct content type support, you should now use the handleRequest method in your actions as shown in the documentation

You can now use the the plugin in your actions like this:

public function executeAmf(sfWebRequest $request) {

  sfAmfGateway::getInstance()->handleRequest();

  return sfView::NONE;

}

There is a lot of stuff coming for the next version of the plugin, so stay tuned :-)

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

3 comments for now

sfAmfPlugin 1.3.0 released

Posted by thaberkern on May 05 2009 | AMF, Flex, General, Symfony, doctrine

Just want to inform you that my sfAmfPlugin for Symfony-Flex-Communication was released in version 1.3.0.

Most noticeable changes:

  • Fixing a bug with PHP Strict mode (thanks to Daniel Holmes for spotting this one)
  • Adding the possibility to store the services in all lib-folders of a project (app, module, project, plugins)
  • Fixing different bugs with AMF conversion of Doctrine objects (thanks to Patrick Schirch for bugging me about them)

I’m still working to get the Doctrine support better, there will be much more about this in the next version of the plugin. Class mapping is also a thing I want to improve a lot. So stay tuned and watch out for future versions :-)

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

no comments for now

UML diagramming without the drawing

Posted by thaberkern on May 03 2009 | General

Not a symfony related blog entry but I ran into this tool yesterday and I pretty like it. So I want to share my finding with you. Maybe you know it: You are working on some documentation in your favorit wiki (trac, redmine…) and you like to add some UML diagramm fragments to it. Switching to a vector drawing or UML-Tool, creating the diagram, saving it as a bitmap graphic, uploading it to the wiki and linking it in the wiki-markup… *phew* A lot of work for a simple task.

It can be done easier :-) Just use yUML for creating the UML fragments. The free service use a different, more declarative, approach.You can add UML via image tags to your blog or wiki.

For example:<img src=”http://yuml.me/diagram/class/[Order]->[Position]”>” /> results in

Of course you can create more complex diagrams like this one (from the yUML documentation).

<img src=”http://yuml.me/diagram/class/[Customer]<>1-orders 0..*>[Order], [Order]++*-*>[LineItem], [Order]-1>[DeliveryMethod], [Order]*-*>[Product], [Category]<->[Product], [DeliveryMethod]^[National], [DeliveryMethod]^[International]”/>

It is surprising, what can be done with this solution

  • Aggregation
  • Relations
  • Composition
  • Inheritance
  • Cardinality
  • Labels
  • Classes with methods and properties

All included.  Beside class diagrams Use cases can created also.

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

6 comments for now

sfAmfPlugin 1.2.3 for Flex/Symfony released

Posted by thaberkern on Apr 16 2009 | AMF, Flex, General, Symfony

Hi,

just for your information: I released the version 1.2.3 of the sfAmfPlugin earlier this day. The new version is a pretty important update so please install the new version.

The most important change is the fix of the bug taht caused problems with the usage of packages for the service classes

Installation as always:

$> symfony plugin:install sfAmfPlugin

If you want more information about the plugin vistit the symfony plugin page or read the the HelloWorld example blog post.

Timo

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

no comments for now

HelloWorld example with Flex and Symfony

Posted by thaberkern on Apr 15 2009 | General

Today I want to show you how to use the sfAmfPlugin to create a simple Hello World application with Symfony, Flex and the plugin. AMF is the most comfortable way to communicate between a backend technology and Flex. AMF allows RMI (Remote Mathod Invocation) from Flex to a backend server that is able to support AMF. The sfAmfPlugin for Symfony adds AMF-support to the PHP-Framework.

What do we want?
Keep it simple! In this small sample project we will create a Flex-Client with a text-field and a button. If the user clicks the button the content of the textfield will be sent to the backend via AMF (we call a service method) and the result from the backend is placed on the screen.

Hello World Flex Client

Symfony Project
First of all we need a Symfony project. We create one with the name “flexdemo” and an application called “frontend”

$> symfony generate:project flextest
$> symfony generate:app frontend

Now it is time to install the plugin. This can be done via the symfony commandline tool:

$> symfony plugin:install sfAmfPlugin
$> symfony cc

Now everything is in place to create our first AMF-Service. Therefore just use a commandline task that comes with the sfAmfPlugin:

$> symfony amf:create-service --package=de.shiftup.flextest HelloWorld
$> symfony cc

This commandline tasks creates a service class in the lib/services folder of your symfony-project. If you used the (optional) –package parameter sfAmfPlugin created a suitable directory-structure. In the case of our simple sample you will find the service-class under lib/services/de/shiftup/flextest/HelloWorldServcie.class.php. Open this file and change the content to the following sourcecode:

<?php
  /**
   * AMF enabled service class HelloWorldService
   *
   * Project: flextest
   *
   * @package   de.shiftup.flextest
   * @author    Timo Haberkern
   *
   * @version SVN: $Id$
   */
  class HelloWorldService extends sfAmfService {

    public function sayHello($who) {
      return "Hello ".$who;
    }
}

The last thing we will need is a AMF-Gateway-Module that we can call via URL. You can create this module as any othe Symfony module:

$> symfony generate:module frontend amfgateway

Open the actions.class.php in apps/modules/amfgateway/actions and change the sourcecode to the following:

<?php
  /**
   * amfgateway actions.
   *
   * @package    flextest
   * @subpackage amfgateway
   * @author     Timo Haberkern <timo.haberkern@shift-up.de>
   * @version    SVN: $Id: actions.class.php 12 2009-04-14 07:12:25Z thaberkern $
   */
  class amfgatewayActions extends sfActions {
    /**
     * Executes index action
     *
     * @param sfRequest $request A request object
     */
   public function executeIndex(sfWebRequest $request) {
      $this->setLayout(false);

      $gateway = new sfAmfGateway();
      $response = sfContext::GetInstance()->getResponse();
      $response->setContent($gateway->service());
      return sfView::NONE;
   }
}

Thats it. This gateway action will check which Service class is called from flex and call the method in the class. Nothing more is needed on the Symfony side of life.

Flex-Client
On the Flex-Side of our small little project we need a project first. Just create a new one. As “Application server type” choose “None”. You can name the Flex project as you want. FlextTestClient will do for us at the moment.

To call AMF-Server-Services you need to configure them to use in a Flex application. This service definition is done in the file services-config.xml. Create this file directly in the src-directory. And add the following XML code to it:

<?xml version="1.0" encoding="UTF-8"?>
<services-config>
  <services>
    <service id="flextest-service"
          class="flex.messaging.services.RemotingService"
          messageTypes="flex.messaging.messages.RemotingMessage">
        <destination id="flextest">
          <channels>
            <channel ref="flextest-channel"/>
          </channels>
          <properties>
            <source>*</source>
          </properties>
        </destination>
    </service>
  </services>
    <channels>
      <channel-definition id="flextest-channel"
            class="mx.messaging.channels.AMFChannel">
        <endpoint uri="http://flextest/frontend_dev.php/amfgateway"
            class="flex.messaging.endpoints.AMFEndpoint"/>
      </channel-definition>
    </channels>
</services-config>

Maybe you will need to change the endpoint-uri to the local URL of your Symfony project.

Now open the Project-Settings of your Flex Project (right click on the project icon->Properties) and select “Flex compiler”. Add the services-config.xml to the compiler options.

Flex Project Settings

Now open the main applictaion file FlexTestClient.mxml. We need to add MXML markup for the Panel with the button and the text input field.

<mx:Panel x="120" y="42" width="281" height="194"
      layout="absolute" title="SayHello">
  <mx:TextInput id="username" x="90" y="10"/>
  <mx:Label x="10" y="12" text="Your Name:" fontWeight="bold"/>
  <mx:Button x="176" y="40" label="SayHello" click="sayHello()"/>
  <mx:Text x="10" y="83" id="result" text="Result"
      width="241" height="61" fontWeight="bold"
      color="#FF0000"/>
</mx:Panel>

Nothing special here. As you can see we call the function sayHello on the click event of the button, so we will need a Script-Block with such a function:

<mx:Script>
  <![CDATA[
    private function sayHello():void {

    }
  ]]>
</mx:Script>

Now we will do what we wanted to do just from the beginning: Callin our serverside Symfony service class and method. Therefore we will use the service definition we have done in the services-conf.xml. Add the following lines to the sayHello function:

var remote:RemoteObject = new RemoteObject("helloworld");
remote.source = "de.shiftup.flextest.HelloWorldService";
remote.sayHello(username.text);

What’s going on here? We initialize a new RemoteObject (given the ID of the service from the service-conf.xml) and define the Symfony-Service-class. Please keep in mind that you need write the full packagename of the Servcieclass (in our case de.shiftup.flextest.HelloWorldService). Now we can call the sayHello-Method of this Serverclass. But what to do with the return value of the Server-Service? AMF Services are assynchronous, so you can not do something like this:

result = remote.sayHello(username.text);

We need to define result event listeners to deal with the different result states (Success and Fault)

private function sayHello():void {
  var remote:RemoteObject = new RemoteObject("helloworld");
  remote.source = "HelloWorldService";

  remote.addEventListener("result", function (event:ResultEvent):void {
    result.text = event.result.toString();
  });
  remote.addEventListener("fault", function(event:FaultEvent):void {
    Alert.show(event.fault.toString(), "Error");
  });

  remote.sayHello(username.text);
}

Your MXML should now look like this:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
	<mx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.rpc.remoting.RemoteObject;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;

			private function sayHello():void {
				var remote:RemoteObject = new RemoteObject("helloworld");
				remote.source = "HelloWorldService";

                remote.addEventListener("result", function (event:ResultEvent):void {
                 	result.text = event.result.toString();
                 });
                remote.addEventListener("fault", function(event:FaultEvent):void {
                 	Alert.show(event.fault.toString(), "Error");
                 });

                remote.sayHello(username.text);
			}
		]]>
	</mx:Script>
	<mx:Panel x="120" y="42" width="281" height="194" layout="absolute" title="SayHello">
		<mx:TextInput id="username" x="90" y="10"/>
		<mx:Label x="10" y="12" text="Your Name:" fontWeight="bold"/>
		<mx:Button x="176" y="40" label="SayHello" click="sayHello()"/>
		<mx:Text x="10" y="83" id="result" text="Result"
				width="241" height="61" fontWeight="bold"
				color="#FF0000"/>
	</mx:Panel>
</mx:Application>

Start your Flex-Application and have fun with your small Hello World application :-)

More service classes
In a real-life project you will have more than one Service-class. But keep in mind: Regardless the amount of service-classes you will always need only one gateway module (amfgateway). This gateway can handle all Service-Classes.

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

18 comments for now

Plugin sfAmfPlugin 1.2.2 released

Posted by thaberkern on Apr 12 2009 | General

Hi,

I have just released the version 1.2.2 of the Symfony Plugin sfAmfPlugin. I fixed the formatting problems in the documentation and fixed the installation problem on symfony 1.2 systems.

BTW: If you like and use the plugin, just add it to your stack (click on I use it)

Timo

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

no comments for now

sfAmfPlugin version 1.2.0 released

Posted by thaberkern on Apr 09 2009 | Flex, General, Symfony

Hi all,

i just released the new version 1.2.0 of the AMF-Plugin for Symfony (http://www.symfony-project.org/plugins/sfAmfPlugin/1_2_0)

There are some new features in this version:

  • Updated SabreAMF to the most current version 1.2.203
  • Added a fix for Service-Classes with packages in the class name
  • More work on comments and documentation
  • Added Symfony 1.2.0 compatibility
  • Added a new commandline-task with that you can create a new Service class

The most important new feature is the new task. You can now create a service class via command line:

$ symfony amf:create-service User will create a file /lib/services/UserService.class.php

$symfony amf:create-service –package=de.shiftup.project User will create  /lib/services/se/shiftup/project/UserService.class.php

Get it while it is hot :-)

As always: Feedback wanted!

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

no comments for now

The best Symfony IDE: PHPEdit

Posted by thaberkern on Apr 05 2009 | Symfony

If you think about the best IDE you will probably think about eclipse with the PDT-Plugin, Netbeans or Kommodo. None of them has special support for the Symfony-Framework. As I wrote in an earlier post I’m using eclipse for my daily work. With some enhancements it is a pretty good IDE for Symfony-Development. Netbeans catched up with the last releases an there is a special Symfony-Support planned in one of the future releases.

Last week there was a new release of the Windows-PHP-IDE PHPEdit. Since Version 3.2 there is an excellent Symfony support in this IDE.  A bunch of features makes the development with Symfony a lot more productive. I couldn’t resist and took a deeper look at this software. It was the first time that I used PHPEdit an I’m surprised on how good it is.

Wizards

PHPEdit has a lot of wizards for creating Symfony-Projects and different Symfony artifacts (i.e. modules, actions…). For developers who dont know all of the symfony command line tasks and all of their parameters, these wizards are a great help.

Project Wizard Command Wizards

Commands

PHPEdit installs a plugin that allows the IDE to get information about all tasks of the current project. The context menu of the project is file-sensitive. So you will get other tasks in the context menu when clicking on a application than clicking on a module or project. All Symfony tasks are available via context menu. Most of them with an upcoming wizard in which you can set the parameters by mouse clicks

Symfony Tasks

Code Completion and Editor

The Editor has everything you can think of and support for all neccessary file formats (i.e. YAML) are included. Code-Folding,Line-Numbers, Smart Idention and others are available. Plus you have a great IntelliSense support. The Editor knows even the Symfony-Framework functions of the classes. You can jump between Actions and View-Template what is solving one of the most annoying problems if you are working on a large project and have a lot of action.class.php files open.

Jump between Action and template IntelliSense

Conclusion

The makers of PHPEdit did a wunderful job. The symfony support is how I it should be in every IDE :-)

Beside of this Framework-Specific features there is all you need for PHP-Development. A good PHP-Editor with IntelliSense and PHP-Debugging, Project management, everything is on board and pretty good. The only drawback is that PHPEdit is not freely available. It has a commercial license starting with 89.- Euros for the basic feature edition. If you are not using windows another drawback is that PHPEdit is only available for windows.

I’m still surprised why I never used this IDE before because it has everything you need for PHP development. Maybe it was because of its commercial license. For now it is the best Symfony IDE. The Framework-Support is outstanding. Lets see how the planned Symfony-Support in Netbeans can compete with this.

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

6 comments for now

German Symfony trainings

Posted by thaberkern on Jan 11 2009 | Model, Propel, Symfony, doctrine, workshop

Hello all,I just anounced the dates and locations for my german symfony trainings/workshops. The workshops take place in Stuttgart, Hamburg and Berlin. Language of the workshops is german. 
You can find more information and prices at the following training-website
Maybe we can see us at one of these events :-)    

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

1 comment for now

Use routing to serve localized and dynamic JavaScript

Posted by thaberkern on Dec 13 2008 | Symfony

Hi all,times are changing. For a lot of my projects I use a JavaScript only Web UI based on toolkits like ExtJs or qooxdoo. These applications are composed of a lot JS-Files located in the web/js folder of the Symfony-project.One of my problems i always had was that I had no chance to use Symfony Helper-Functions in those files. Especially the I18N and URL-Helper functions were missed badly.Over the time I came up with a solution the works great for me. Maybe it is usefull for you too… Continue Reading »

Book Mark it->del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Windows Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

2 comments for now

Next »