Installation
Step 2 - Start developing (PHP side)
Step 3 - Create your App (Flex side)
Download Sphex
http://code.google.com/p/sphex/
Extract the Tar Gzip file (on windows you may use 7-Zip)
gunzip -c sphex-1.0.tar.gz | tar xopf -
All the files permissions should be fine, but if something's bad or you upload all the files, run these commands or use your FTP client (needed for unix only):
cd sphex-1.0
chmod 777 logs/
chmod 766 autoload/autoload_index.php
chmod -R 777 models/generated/
cd ../example/
chmod 777 database/sphexample.db
That's it, you can now create your Rich Internet Application !
Go and test it out, check the example, just point your browser on your Sphex folder
http://yourserver.com/thesphexdir/example/
On this Flex example, right click to view the source and figure out all the AS3 Code used behing the scenes.
Step 2 - Start developing (PHP side)
Setup the config file (config.php)
You will find this file in the config folder of Sphex, edit it, and change what you need.
SPHEX_DIR: You don't need to change that
SPHEX_DATABASE_PDO_DSN: Set your DSN, for info see: http://www.php.net/manual/en/pdo.connections.php
SPHEX_DATABASE_TABLE_PREFIX: Set if you want to use a prefix before all your table names
SPHEX_AUTOINDEX_MODE: Set to 'dev' or 'prod'
prod mode: on the first run, all the classes are found and sphex create an autoload_index.php file, then, sphex will always use this file to fast up things. If you add some new classes in the vendors, models, services or classes folder, just empty or delete the file (autoload/autoload_index.php), it will be recreate automatically.
dev mode: all the classes are found in the sphex predefined folders and created on the fly
SPHEX_ERROR_REPORTING: Set to true or false, if you want to hide errors to flex in production mode, set this to false
SPHEX_AUTOINDEX_TREETYPE_FOLDER_X
SPHEX_AUTOINDEX_TREETYPE_FOLDER_X_SEPERATOR: If you use some projects that use the directory structure for naming their classes, Sphex will indexes those classes correctly.
Doctrine is a good example:
'Doctrine/Locking/Manager/Pessimistic.php' file become a class named 'Doctrine_Locking_Manager_Pessimistic'
SPHEX_SESSION_PREFIX: If you want to change the name of the session variable
SPHEX_PROTECTION_ENABLED: If you don't need to protect your services, set this to false for faster results
SPHEX_LEVEL_KEY: With level protection, set this to tell Sphex which field from your user row to use to get his level, or set this to an empty string to set the level manually in your own login code.
Generate all your Model classes, just point your browser at the genmodels.html
http://yourserver.com/thesphexdir/example/genmodels.html
Click on the button
Go to the 'models/generated' folders and move in the 'models' folder all the Model classes and BaseModel that you need and don't forget to delete the ones you don't want from the generated folder. This folder (models/generated) need to be cleaned, delete all the php files manually or use these commands:
cd sphex/models/generated
find . -name "*.php" -exec rm '' \;
Create your services (public functions from classes in the services folder)
Every functions that you create in any classes in the services folder will become available for your Flex Application with the name of the class dot the function, like 'Users.getList' or whatever.
Protect your services
See: Services Protection
Step 3 - Create your App (Flex Side)
Set the services param in your Flex Project Properties
Right click on your project in Flex Navigator, go to Flex Compiler menu and add this string in the field named 'Additional compiler arguments':
-services yoursphexfolder\config\services-config.xml
Make SphexResponder.as available to your App
You can find this file by right-clicking on the example application and View Source, or in the sphex_example.zip that you will find in the Sphex package (in the example\srcview folder)
Add a RemoteObject to your base MXML
<mx:RemoteObject id="sphex"destination="sphex" />
Initiate the RemoteObject with the choosen id
SphexResponder.init(sphex);
Call a service
SphexResponder.request( 'ExampleClass.anyFunction', parameters, successFunction, errorFunction );