PDA

View Full Version : Ext.Direct for Zend Framework



axpa
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.
Cheers
Axpa

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

Now running with ZF 1.10.

// Axpa

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.
from
$method ['len'] = $matches [1];
into
$method ['len'] = (int)$matches [1];

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

ddanatzko
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?

axpa
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.
cheers
Axpa

sekundek
12 Mar 2010, 9:47 AM
Hi,

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?

regards

axpa
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

vahid4134
21 Jul 2010, 2:11 AM
very goooooooood

axpa
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.
/axpa


<?php

/** 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)
{
parent::__construct($uri);

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

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

}

}