diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1adc831 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +# Created by .ignore support plugin (hsz.mobi) \ No newline at end of file diff --git a/README.md b/README.md index c70ab1e..758b4e2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,347 @@ # ExtDirect.php Extremely Easy Ext.Direct integration with PHP + + +[Created by: J. Bruni](http://www.sencha.com/forum/showthread.php?102357-Extremely-Easy-Ext.Direct-integration-with-PHP) + + +How to use: +=========== + +1) PHP + +PHP Code: + + + +Here, "Server" is the PHP class that we want to provide access from the JavaScript code. It could be any other class. + +2) HTML: + +Code: + + + +Here, "ext-direct.php" points to the PHP file shown on item 1. The "?javascript" query string is necessary, because the default output is on JSON format (good for Ext Designer). + +3) JavaScript: + +Code: + + Ext.php.Server.date( 'Y-m-d', function(result){ alert( 'Server date is ' + result ); } ); + +Here, to call the "date" method from PHP "Server" class, we prepended the default namespace Ext.php. The first parameter is the $format parameter. The second parameter is the JavaScript callback function that will be executed after the AJAX call has been completed. Here, an alert box shows the result. + + + +What are you waiting for the download? +-------------------------------------- + +It includes: + +- ExtDirect.php - This is the file you include in your PHP script. +- example.php - This is a working sample (PHP part). example.html - The +- HTML and JavaScript parts of the working sample. + +Features +-------- +- API declaration with several classes (not limited to a single class) + +- API "url", "namespace" and "descriptor" settings ("ExtDirect" class assigns them automatically if you don't) + +- Two types of API output format: "json" (for use with Ext Designer) and "javascript" (default: json) + +- You choose if the "len" attribute of the actions will count only the required parameters of the PHP method, or all of them (default: all) + +- You choose whether inherited methods will be declared in the API or not (default: no) + +- You choose whether static methods will be declared in the API or not (default: no) + +- Instantiate an object if the called method is static? You choose! (default: no) + +- Call the class constructor with the actions parameters? You choose! (default: no) + +- "debug" option to enable server exceptions to be sent in the output of API action results (default: off) + +- "utf8_encode" option to automatically apply UTF8 encoding in API action results (default: off) +- Handles forms +- Handles file uploads + +Configuration - How To +---------------------- + +Easy. + +If the configuration option name is "configuration_name" and the configuration value is $value, use this syntax: + +PHP Code: + + ExtDirect::$configuration_name = $value; + +And that's all. + +Now, let's see the available configuration options: + +- name: api_classes +- type: array of strings +- meaning: Name of the classes to be published to the Ext.Direct API +- default: empty +- comments: This option is overriden if you provide a non-empty $api_classes parameter for the "ExtDirect::provide" method. Choose one or another. If you want to declare a single class, you can set $api_classes as a string, instead of an array. +- example +PHP Code: + + ExtDirect::$api_classes = array( 'Server', 'OtherClass', 'StoreProvider' ); + +- name: url +- type: string +- meaning: Ext.Direct API attribute "url" +- default: $_SERVER['PHP_SELF'] +- comments: Sometimes, PHP_SELF is not what we want. So, it is possible to specify the API URL manually. +- example +PHP Code: + + ExtDirect::$url = '/path/to/my_php_script.php'; + + +- name: namespace +- type: string +- meaning: Ext.Direct API attribute "namespace" +- default: "Ext.php" +- comments: Feel free to choose your own namespace, according to ExtJS rules for it. +- example +PHP Code: +ExtDirect::$namespace = 'Ext.Dharma'; +- name: descriptor +- type: string +- meaning: Ext.Direct API attribute "descriptor" +- default: "Ext.php.REMOTING_API" +- comments: Feel free to choose your own descriptor, according to ExtJS rules for it, and to the chosen namespace. +- example +PHP Code: +ExtDirect::$descriptor = 'Ext.Dharma.REMOTING_API'; +- name: count_only_required_params +- type: boolean +- meaning: Set this to true to count only the required parameters of a method for the API "len" attribute +- default: false +- example +PHP Code: +ExtDirect::$count_only_required_params = true; +- name: include_static_methods +- type: boolean +- meaning: Set this to true to include static methods in the API declaration +- default: false +- example +PHP Code: +ExtDirect::$include_static_methods = true; +- name: include_inherited_methods +- type: boolean +- meaning: Set this to true to include inherited methods in the API declaration +- default: false +- example +PHP Code: +ExtDirect::$include_inherited_methods = true; +- name: instantiate_static +- type: boolean +- meaning: Set this to true to create an object instance of a class even if the method being called is static +- default: false +- example +PHP Code: +ExtDirect::$instantiate_static = true; +- name: constructor_send_params +- type: boolean +- meaning: Set this to true to call the action class constructor sending the action parameters to it +- default: false +- example +PHP Code: +ExtDirect::$constructor_send_params = true; +- name: debug +- type: boolean +- meaning: Set this to true to allow exception detailed information in the output +- default: false +- example +PHP Code: +ExtDirect::$debug = true; +- name: utf8_encode +- type: boolean +- meaning: Set this to true to pass all action method call results through utf8_encode function +- default: false +- example +PHP Code: +ExtDirect::$utf8_encode = true; +- name: default_api_output +- type: string +- meaning: API output format - available options are "json" (good for Ext Designer) and "javascript" +- default: "json" +- comments: Another way to enforce "javascript" output is to append the "?javascript" query string in the end of your PHP script URL; do this in the HTML