View Full Version : Ext.Direct for Zend Framework

1 Feb 2010, 6:28 AM
Hi Exters,
After looking around for a Zend Framework stack I decided to create one myself.
This is version 0.1. (That is it's my first work with ZF ever and my first working draft)

The code is attached in the extjsstack.zip
Tested with ExtJs 3.1 & and ZF 1.9.

Small Howto:
If you use zf.bat/zf.sh you can take a look at the attached .bat file (just a collection of creates)
Then you extract the Extjs folder and place it in Library.
There's a extdirect.ini file in the application/configs that needs adjusting according to your needs.
Also take the settings needed from application.ini and place it in your own.
Then you have an ExtdirectController.php in controllers and views respectively.
You also need the init function from the Bootstrap file.

You can test it by pointing the direct.php in extjs tests to use "/extjsstack/public/extdirect/getapi" instead of php/api.php. (of course you might have another root than /extjsstack).

Currently supported:
getapi: uses introspect to reads the metadata, based on extjs php api, for example please see the TestactionController.php
Form & regular remoting requests, batched or not, should work, Upload and caching not yet implemented, polling not tested.

Please share your improvements or bugfixes.

3 Feb 2010, 12:40 AM
I found 2 bugs, i've attached a new version here.
- argLen didnt get a value of 0 by default
- $methods array didnt get cleared in foreach

Now running with ZF 1.10.

// Axpa

3 Feb 2010, 1:17 AM
If you send params you need to fix the following line 72 in file ExtdirectController.php in the second zipfile.
$method ['len'] = $matches [1];
$method ['len'] = (int)$matches [1];

else you get an error "this.onRead is not a function".

2 Mar 2010, 12:50 PM
Hey Axpa,

I am in the process of writing an App with ZF 1.10 and Ext3.1. I am using the modular directory structure as oppposed to the standard dir structure for ZF. The Ext.Direct stack you've written for ZF is for the latter of the two. You stated in the OP that this was your first venture into ZF, but I was wondering if you have looked at porting the code over to the modular structure yet?

Also, I'm having trouble understanding the placement of this line within the Bootstrap class:

$request = new Extjs_Controller_Request_RawJson ();

This appears before the call to the isXmlHttpRequest () method of the frontcontroller. This would mean that the Extjs_Controller_Request_RawJson class would be instantiated EVERY time the app is bootstrapped. If the application has areas that do not require the Ext.Direct API class in order to render a response, wouldn't this be performing unnecessary work on the Server Side?

3 Mar 2010, 12:12 AM
Hi ddanatzko,
Hi havent gotten to the modular directory structure yet, currently the standard dir does what I need, I might revise this in the future
In my scenario I currently only use ZF to send JSON to Ext so thats not an issue, but your right bootstrapping that leads to overhead if you use it in a mixed setup.
Please feel free to share any changes to my code into making it work in your modular setup.

12 Mar 2010, 9:47 AM

i've check the code and I have one question. Would be possible for some kind of Json Server extension. I kinda don't understand the whole code, especialy in boostrap. Isn't only one action needed for all remoting thing.

I'm using at the moment JSON server and than on a client side in need to make some changes in provider. The only thing that needs to be change on server to make this with standard remoting provider in altering definition and processing request the right way.

What do you think about that? Does it make any sense?


15 Mar 2010, 2:46 AM
Hi Sekundek,
Yes you can put everything in bootstrap into one method.
As for your other questions can you explain a bit more? I cant understand what you mean.
Best regards

21 Jul 2010, 2:11 AM
very goooooooood

29 Jul 2010, 1:53 PM
Hi, Just a short bugfix, I added a case in the switch far below.
I will post a new zip as soon as I implement the upload "post" form.


/** Zend_Controller_Request_Http */
require_once 'Zend/Controller/Request/Http.php';

/** Zend_Uri */
require_once 'Zend/Uri.php';

* Extjs_Controller_Request_RawJson
* @uses Zend_Controller_Request_Http
* @package Zend_Controller
* @subpackage Request
* @todo Currently it only adds the RAW data it should allow for selecting sources, it doesnt right now.
class Extjs_Controller_Request_RawJson extends Zend_Controller_Request_Http
protected $_paramSources = array('_GET', '_POST','_RAW');
protected $_rawPrefix = 'RAW_';
* @var integer count of requests in rawdata
public $requestCount = 0;
* Constructor
* If a $uri is passed, the object will attempt to populate itself using
* that information.
* @param string|Zend_Uri $uri
* @return void
* @throws Zend_Controller_Request_Exception when invalid URI passed
public function __construct($uri = null)

$rawBody = $this->getRawBody();
if($rawBody !== false){
$json = Zend_Json::decode($rawBody, Zend_Json::TYPE_ARRAY);
} catch (Exception $ex) {
$json = false;
$json = false;
if($json !== false && is_null($json) !== true){

$this->requestCount = 1;
$json2[] = $json;
$json = $json2;
$this->requestCount = count($json);
$this->setParam("RawJson", $json);
$req = $this->getParams();
$this->requestCount = 1;
$json = array();
$params = array();
foreach ($req as $pname => $pval){
switch ($pname){
case 'extAction':
$pname = 'action';
case 'extTID':
$pname = 'tid';
case 'extType':
$pname = 'type';
case 'extMethod':
$pname = 'method';
$params["$pname"] = $pval;
$json[] = $params;
$this->setParam("RawJson", $json);