Flextrine 0.7 released – now with ZendAMF!

After much soul searching I eventually decided to put in the time to convert Flextrine from using AMFPHP to ZendAMF.  There were a few reasons I decided to make this move, but eventually it boiled down to the fact that quite a few people had asked me to do so.  In retrospect it was certainly the right thing to do – ZendAMF has the green light from Adobe, its licence is LGPL instead of GPL and the cleaner code base means that the changes Flextrine requires can be implemented as overridden classes instead of having to modify the ZendAMF core.  This particularly is great news because it means that you can use Flextrine directly with the standard Zend framework installation, whereas previously you could only use the version of AMFPHP bundled with Flextrine.

Functionally speaking things remain exactly the same, and we continue to approach our stable release alongside Doctrine 2.

The new version of Flextrine can be downloaded from www.flextrine.com.  Note that if you are upgrading from a previous version of Flextrine you will need to regenerate your AS3 entities.

Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating the entities

Introduction
Setting up the server
Creating the entities
Creating the database schema
Loading the entities
Creating new entities
Deleting entities
Updating entities
Conclusion

Now that Flextrine has been configured we need to create our entities.  Entities are the objects that we want to enable for reading and writing to the database, and they are defined in PHP in the entities directory of the Flextrine server side component.

The requirements for our simple address book are that we need to have groups containing contacts.  Unfortunately Group is a reserved word in SQL so we’ll call it ContactGroup.  ContactGroups have a name, and many Contacts, and Contacts have a name, telephone number, birthday and a contactGroup.  We are going to place all our entities in the vo package.  This gives us the class diagram below:

Flextrine entities

Create a folder called vo in the entities directory of the Flextrine server side component and create ContactGroup.php and Contact.php with the contents given below.  More information on writing entities can be found in the Doctrine documentation for Basic Mapping and Association Mapping.  The main thing to remember when creating entities is that:

  • All mapped attributes must be public

ContactGroup.php

<?php


namespace vo;


use DoctrineCommonCollectionsArrayCollection;


/**

 * @Entity

 */


class ContactGroup {


    /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */

    public $id;


    /** @Column(length=100, type="string") */

    public $name;


    /**

     * @OneToMany(targetEntity="Contact", mappedBy="contactGroup")

     */


    public $contacts;


    public function __construct() {

        $this->contacts = new ArrayCollection();

    }


}


?>

Contact.php

<?php

namespace vo;


use DoctrineCommonCollectionsArrayCollection;


/**

 * @Entity

 */


class Contact {


    /** @Id @Column(type="integer") @GeneratedValue(strategy="IDENTITY") */

    public $id;


    /** @Column(length=80, type="string") */

    public $name;


    /** @Column(length=50, type="string", nullable="true") */

    public $telephoneNumber;


    /** @Column(type="date", nullable="true") */

    public $birthday;


    /**

     * @ManyToOne(targetEntity="ContactGroup", inversedBy="contacts")

     */

    public $contactGroup;


    public function __construct() {


    }


}


?>

Now that we have created our entity definitions we need to create the matching database schema.