PureMVC Port of Keith Craigo's Flex + Zend_Amf + Zend_Auth + Zend_Acl + Zend_Session · Apr 10, 08:23 PM

This is an advanced topic made simple by Keith Craigo. His original demo used the Cairngorm MVC framework to demonstrate a Flex Login form interacting with Zend_AMF with authentication, access control, and session id’s.

Download

Download AccessControlExampleSessionsPMVC.zip Here

Intro

My version is supposed to be a straightforward port of the original, using PureMVC instead of Cairngorm for the MVC part of it, but I kept the Cairngorm ServiceLocator class for the AMF interaction. Therefore, the project in fact combines PureMVC and Cairngorm. This is my first foray into MXML, data-binding, and Zend PHP, so if you have any suggestions I’d love to hear them.

The source zip includes both versions of the Flex client within the src folder. Except for the main mxml files, all the PureMVC files are in the src/app folder and all of the Cairngorm files are in the src/com folder. Also included are two FlashDevelop as3proj, it’s possible you might have to fiddle with the classpaths to get them to compile on your machine.

This is a good opportunity to get a quick glance at the different folder structures of Cairngorm and PureMVC projects:

Observations

  • I think we can ignore the fact that the PureMVC version has many more files than the Cairngorm version does. We could easily combine all the mediators into one mediator, and do the same with the proxies and commands. However, you’re probably not actually going to make an app this small so all the separate classes will come in handy.

  • Notice how the PureMVC version stores events in an events folder under view. If we needed to, we could also create an events folder under model. In PureMVC, view events are not consumed by the model and vice versa.

  • The Services.xml file is part of the Cairngorm ServiceLocator

  • Abandoning the ModelLocator pattern used in Cairngorm for persistent proxies and VOs is more elegant, intuitive, and provides better separation of code.

Installation Overview

You should read Keith’s blog entries for additional information. I’m going to try to make this quick for you:

  • Open the included sql.txt file (also shown below) and use it to create the data in your database.

  1. CREATE TABLE IF NOT EXISTS 'admin' ('username' varchar(20)
  2. NOT NULL,'password' varchar(20) NOT NULL,'realfirstName'
  3. varchar(20) NOT NULL,'reallastName'
  4. varchar(20) NOT NULL,'role' varchar(20)
  5. NOT NULL,PRIMARY KEY ('username'))
  6. ENGINE=InnoDB DEFAULT CHARSET=latin1;
  7.  
  8. INSERT INTO admin VALUES('admin', 'password','admin', 'admin', 'admin');
  9. INSERT INTO admin VALUES('manager', 'password','manager', 'manager', 'manager');
  10. INSERT INTO admin VALUES('Super', 'password','Super', 'Super', 'Super');
  11. Download this code: /files/sql.txt

  • Modify php/utils/ConnectionHelper.php (also shown below) to reflect your database configuration

  1. <?php
  2. class ConnectionHelper {
  3. public function __construct() {
  4. $this->host='localhost';
  5. $this->dbname='accesscontrolexample';
  6. $this->username ='root';
  7. $this->password = '';
  8. }
  9. }
  10. ?>
  11. Download this code: /files/ConnectionHelper.txt

  • Copy the contents of the php folder to a new folder on your server. This folder will house the Zend_AMF Service.

  • In folder created in previous step, add library folder and then copy the Zend Framework and Zend_AMF into the library.

  • Edit services-config.xml to point to your Zend server configuration.

  • Compile the Flex app.

Additional Resources

PureMVC Forum: Integrating Adobe AIR, Cairngorm, PureMVC, LiveCycle Data Services , Hibernate

PureMVC Forum: Services Locator pattern

PureMVC Forum: Who should call the delegates: proxys or commands?

PureMVC Forum: PureMVC proxy/model singleton vs. Cairngorm ModelLocator?

PureMVC Forum: Who should call the delegates: proxys or commands?

— Pickle

---

Comment

Textile Help