« Flextrine Tutorial – CRUD in a simple Flex 4 address book: Setting up the server
» Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating the database schema

AMFPHP, Actionscript 3.0, Flex 4, Flextrine, PHP

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

08.03.10 | Comment?

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:

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 Doctrine\Common\Collections\ArrayCollection;

 

/**

 * @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 Doctrine\Common\Collections\ArrayCollection;

 

/**

 * @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.

Social bookmarks:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google

have your say

Add your comment below, or trackback from your own site. Subscribe to these comments.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

:

:


« Flextrine Tutorial – CRUD in a simple Flex 4 address book: Setting up the server
» Flextrine Tutorial – CRUD in a simple Flex 4 address book: Creating the database schema