View Full Version : Ext.Direct for Kohana 3

2 Jun 2010, 2:57 AM
This Kohana 3 module is a port of the Ext.Direct PHP - Maintained by tommymaintz (Tommy Maintz) (http://extjs.com/forum/showthread.php?t=68186)
Built on Kohana v3.0.5

1. Download the attached zip
2. Extract the "extdirect" folder into your modules folder
3. Enable the module in your bootstrap like so
extdirect' => MODPATH.'extdirect'The api JavaScript src will now become http://yourkohanasite/extdirect/api
<script type="text/javascript" src="http://yourkohanasite/extdirect/api"></script>The router can be accessed via http://yourkohanasite/extdirect/router

Some Examples?
I have also ported over and included the Ext.Direct examples that come with ExtJS so you can see it working right away on your setup, to access them visit http://yourkohanasite/extdirect/examples

I have moved the configuration options to config files, take a look in the "extdirect/config" folder to add class paths and api specific options.

[12 March 2011]
* Updated examples to work on Kohana 3.0.x and 3.1.x branches
[10 June 2010]
* Removed restful: true flag from DirectStore, not required
* Store only reloads on create/destroy actions now to update PagingToolbar
* enable_examples now unsets the UserActions example class as well when set
[9 June 2010]
* Added New example (Ext.Direct DataGrid, DirectStore, RowEditor with Kohana ORM)
* Fixed camelcase config variable names with _
* Merged the extdirect and api configs into one (Update existing setups if
overwriting a previous version)
* Added enable_examples flag so you can turn off examples in production sites
Setting it to FALSE will disable the routes and unset the first 2 api
config variables so that the example classes are not included in your api
output when overriding the config in your application.

2 Jun 2010, 11:51 AM
Thanks for the contribution. I've added your stack to the master list.

31 Aug 2010, 4:10 AM
I Start use this module with Kohana 3.0.7. All examples not working, because of variable "$GLOBALS" is filtering in this release. For using this module with Kohana 3.0.7 file $KOHANA_HOME/system/classes/kohana/core.php must be edited.

Find the following code:

// Remove the standard global variables from the list
$global_variables = array_diff($global_variables, array(

And add 'HTTP_RAW_POST_DATA', to the end of this array;

15 Nov 2010, 3:10 AM
Hey mrgloba,

Just tried it out with Kohana 3.0.8 and had no issues with the examples. It's core $global_variables are the same as 3.0.7

Just curious what examples failed for you and what errors you received.


16 Jan 2011, 7:56 AM
I know this is an old thread but I am having problems.

I downloaded Kohana 3.0.9 and extracted it. Went to http://www.mydomain.com/kohana/index.php to verify I had things set up. I then removed install.php.

I downloaded the module and extracted it to http://www.mydomain.com/kohana/modules/

I edited my bootstrap.php file to include the extdirect module as specified above.

I then tried to go to http://www.mydomain.com/kohana/index.php/extdirect/api expecting to see JavaScript however I got an error. I have attached a screen shot of the Kohana errors I got. What am I doing wrong?

16 Jan 2011, 5:29 PM
I solved this problem. What was happening is that I had my bootstrap.php setup wrong. I had kohana in a folder named kohana so I had to modify bootstrap.php to look in that folder:

'base_url' => '/kohana/',
'index_file' => ''

And as you can see, I have my rewrite working also. Here is what I have in my .htaccess to get it working in case others want to know:

RewriteEngine On
RewriteBase /kohana/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /kohana/index.php/$1 [L]

23 Feb 2011, 2:00 PM
Hi. i have small problem with this,
my api is:

Ext.ns('Ext.app'); Ext.app.REMOTING_API = {"url":"\/project\/extdirect\/router","type":"remoting","actions":{"Controller_Uzivatel":[{"name":"action_create","len":0},{"name":"action_update","len":1},{"name":"action_delete","len":1}]}};

but response is still null :-(

3 Mar 2011, 5:15 PM
Hey sadek.daniel,

It would be difficult for anyone to debug why the data is null without looking through you logic for fetching and returning the data.

I guess a good starting point would be to ensure that the examples are working for you.

4 Mar 2011, 1:42 PM
Rather, the question properly and I call my controller function.

My idea is to have compatible extdirect controller with classic Kohana controller.

Controller "classes/uzivatel.php"

<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Uzivatel extends Controller {

public function action_index() {
$uzivatele = new Model_Uzivatel();

echo $uzivatele->email;


// $this->request->response = 'hello, world!';

* @remotable
public function action_create() {
$uzivatel = new Model_Uzivatel();

$uzivatel->email = 'lklllkk';


// $this->request->response = json_encode($uzivatel);
// echo 'asdasd';

return array(
'success' => true,
'data' => array(
// 'foo'=>$foo,
'name'=>'Aaron Conran',
'company'=>'Ext JS, LLC',
// print_r();

Config "config/extdirect.php"

<?php defined('SYSPATH') or die('No direct access allowed.');

return array(
'defaults' => array(
'enable_examples' => FALSE, // You may want to disable examples for a production site
'auto_include' => TRUE, // if you want to use this you have to make sure that your classes (without the prefix)
// are named consistent with the filename and that only one class exists in each file.
'cache_enabled' => FALSE, // expects api_cache.txt to be created and in the module cache folder
// sometimes its helpful to disable during testing
'base_path' => APPPATH.'classes',
// 'namespace' => '', // Default Ext.app
// 'descriptor' => '', // Default Ext.app.REMOTING_API
'api' => array(
'Uzivatel' => array('prefix' => 'Controller_'),
// 'Controller_Uzivatel'
And JS

Ext.onReady(function() {
// Slow the buffering down from the default of 10ms to 100ms
// Ext.app.REMOTING_API.enableBuffer = 100;


Uzivatel.action_create(function(result, e){
console.log(result, e);

and Apache Error Log

[Fri Mar 04 23:14:49 2011] [error] [client ::1] PHP Fatal error: ExtDirect_Router::rpc(): Failed opening required '/home/daniel/workspace/1ad.cz/application/classes//Uzivatel.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/daniel/workspace/1ad.cz/modules/extdirect/vendor/ExtDirect/Router.php on line 97, referer: http://localhost/1ad.cz/

9 Mar 2011, 11:00 AM

here is updated module for Kohana 3.1.x :)

9 Mar 2011, 11:03 AM

here is updated module for Kohana 3.1.x :)

Thanks, what changes have you made as I am using the original one with 3.1.1 right now.

9 Mar 2011, 12:09 PM
Twor or maybe three small fixes were needed:

- extdirect (action_poll)
- examples (action media)

From 3.0.x -> 3.1.x migration guide:

$this->request->response = 'foo';

changed to


I think that's pretty much all i've done ;) + few bracket fixes to suit kohana coding style better.

11 Mar 2011, 5:46 AM
Rather, the question properly and I call my controller function.

My idea is to have compatible extdirect controller with classic Kohana controller.

I see, not sure how that would work. This was a straight port of an existing implementation so direct classes are separate but within Kohana so you can use it's internal methods.

11 Mar 2011, 6:55 AM

here is updated module for Kohana 3.1.x :)

Thanks for the heads up AsYlum.

I have updated the main download to conditionally check Kohana versions and apply the correct request methods for the media action and examples controller so they work for both 3.0.x and 3.1.x branches.

12 Mar 2011, 3:40 AM
I see, not sure how that would work. This was a straight port of an existing implementation so direct classes are separate but within Kohana so you can use it's internal methods.

I'm concerned mainly about the opportunity to offer users the same functionality without JS, which they have with ExtJS, I think it could work, I just came across a problem. Can you please advise me how to handle this?

Argument 1 passed to Controller::__construct() must be an instance of Request, none given, called in /home/daniel/workspace/1ad.cz/modules/extdirect/vendor/ExtDirect/Router.php on line 175 and defined...

4 Jul 2011, 8:48 AM
This doesnt work for Ext.Designer at the moment, correct? Has anyone extended it to JSON only for support of ext designer?

I'm looking into that presently but I confess i'm still quite lost...


7 Jul 2011, 4:31 AM
Hey there,

Liking this module. Thanks for sharing. A couple of tweaks for 3.1 though:

Controller_ExtDirect line 66:


$this->request->headers['Content-Type'] = 'text/javascript';Add:

if (version_compare(Kohana::VERSION, '3.1', '<'))
// Kohaha 3.0.x request API
$this->request->headers['Content-Type'] = 'text/javascript';
// Kohaha 3.1.x request API
$this->response->headers('Content-Type', 'text/javascript');

Also I have read that in order to work with ExtDesigner we need the option to output the API as JSON only. So in ExtDirect_API's _print() method on line 235 I added the following to the start of the function:

if(Request::current()->query('format') == 'json')
echo json_encode($api);
So then navigating to http://webserver/extdirect/api?format=json now only returns the JSON.

Hope this helps, and if anyone thinks I've got the wrong end of the stick somewhere with that last one, do share as I've only been playing with this stuff for 3 hours!


19 Jul 2011, 7:27 PM
Please publish some examples wich demonstrate how to work with kohana ORM from Ext JS 4 models and stores.
I am a newby in the web programming and may be dont understand some facts, wich simple for your, but when i go to direct_grid_orm on my test syte (http://lab.ukrnavi.com/examples/direct_grid_orm) and then type into firebug console

I was confused because it sade me "3.2.1"

Help me please - just for start whith ExtDirect for Ext JS 4.

13 Oct 2011, 2:02 PM

I've just found that if You have caching on server for javascript when first time you load app with fresh browser You won't get router processed.
That's why:

$ext_state = $this->session->get('ext-direct-state');
if( ! isset($ext_state))

$api = new ExtDirect_API();
You do initiate action_api, but You don't use what it produces. Should get $ext_state after that:

$ext_state = $this->session->get('ext-direct-state');
if( ! isset($ext_state))
$ext_state = $this->session->get('ext-direct-state');

$api = new ExtDirect_API();

20 Apr 2013, 10:05 PM
Is this working with Kohana 3.3 ? I need it for a course project.