Apr
16
2009
--

sfAmfPlugin 1.2.3 for Flex/Symfony released

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

Apr
15
2009
--

HelloWorld example with Flex and Symfony

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

Apr
12
2009
--

Plugin sfAmfPlugin 1.2.2 released

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

Apr
11
2009
0

6 Gmail Lab Features you should try

So I’m going though my Settings in my Gmail account and I notice a tab called “Labs”.  Interesting I think to myself and click on it and it seems the Gmail Gnomes have been slaving away at the nifty little options in their experimental features for Gmail.  Here are 6 Gmail Lab Features you should try:

YouTube previews in mail
Ever get a YouTube video in your email from a friend that asks you to  “Hey man, check this out!”?  Well now if you turn on this Gmail lab feature the link will expand inside the Gmail page.  You won’t have to navigate away from your message and have to wait for Gmail to reload your Inbox, its all right there in your message.

Flickr previews in mail
Just like the YouTube video in your message if you have photophiles that are always sending you their newest photos in their favorite Photo Streams then this is for you.  Expands Flickr links inside your message for you to preview.

Fixed width font
Are you old school and hate the default Ariel font?  Can’t align your ‘text tables’ right?  Well then this Gmail Lab feature is for you.  You can now have an option to view your messages in fixed with font like Courier.  Great ready for some ASCII art!

Default ‘Reply to all’
Always find yourself having to select the ‘Reply to all’ option at the bottom of a message because the top right button in each message is plane plane ol’ ‘Reply’?  Well, now you can change that option to be ‘Reply to all’ to the enjoyment of all your friends and family I’m sure.

Mail Goggles
Have you ever sent a message late at night to your friends or co-workers after a long night of drinking?  Are you an alcoholic?  Well then this Gmail Lab feature maybe for you.  When you have this feature activated you’ll be prompted to do basic math when sending a message during predefined time periods (customizable).  If you are inebriated that message won’t go out because you’re too smashed to know what 8 x 7 is.

Undo Send
OOPS did I just send that…unsend unsend unsend!!!  If you find yourself sending a message and needed to unsend that last message because of a misspelling, bad link, or accidentally sending it to the wrong person then you can turn on this little nifty Gmail Lab feature to give yourself 5 seconds to undo that sent message.

Apr
09
2009
--

sfAmfPlugin version 1.2.0 released

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

Apr
05
2009
0

The best symfony IDE for Mac: Probably still Zend Studio

So in a recent symfony-zone article about “the best Symfony IDE: PHPEdit“, the author recommended using PHPEdit.   Problem is PHPEdit doesn’t have a Mac OS X version according to their requirements page as of this date.

So for now using Zend Studio or BBEdit is probably your best bet.  Haven’t tried Netbeans, but at least one developer I know still uses it.  Of course you could just use vi if all else fails.

One last thing, Zend Studio probably won’t ever have any first party support for symfony being that Zend Studio’s parent company has their own framework; so I would’t hold my breath for that.

Apr
05
2009
0

How Twitter could change Live News Feeds

When US Airways 1549 went down in the Hudson River yesterday, some of the first pictures of the event were posted via Twitter, the online and mobile messaging system that allows users to instantly post 140-character missives as well as hyperlinks to pictures and web pages. Twitter has, in effect, given anyone with a cell phone the ability to send immediate, eyewitness news updates out over a public wire.

Now, Yahoo is using the immediacy of Twitter to make its own news service better: the company’s researchers have launched a simple search engine called TweetNews that ranks Yahoo News stories by using information about the most recent, frequently-tweeted topics on Twitter.

Source: Yahoo Uses Twitter To Filter The News

With nearly all the major cell phone carriers supporting some kind of Twitter integration and nearly every mobile phone having video and audio capabilities it really is no surprise.  How soon will major news agencies start using these tweets of live new events?  Will the audacious reporter on the scene be replaced with the happless bystander?

Its only a matter of time live video feeds will be common place especially with 4G coming around the corner.

Written by in: Tech | Tags: ,
Apr
05
2009
--

The best Symfony IDE: PHPEdit

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

Apr
03
2009
0

Reading Now: The Definitive Guide to symfony

The Definitive Guide to symfony

The Definitive Guide to symfony

Well after my last book, I’m now reading The Definitive Guide to symfony.

My new job has me working with the symfony Framework instead of the Zend Framework I used to use.

Here’s an excerpt from the book:

Why ‘symfony‘ and not ‘FooBarFramework’? Because Fabien wanted a short name containing an s, as in Sensio, and an f, as in framework–easy to remember and not associated with another development tool. Also, he doesn’t like capital letters. symfony was close enough, even if not completely English, and it was also available as a project name. The other alternative was ‘baguette’.

Written by in: Books,symfony | Tags: ,

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com