Rovak / KJSencha

Ext-JS / Sencha Touch Integration Module for Zend Framework 2
Other
24 stars 15 forks source link

[WIP] Feature/component generator #11

Closed Rovak closed 11 years ago

Rovak commented 11 years ago

KJSenchaExample Branch: https://github.com/Rovak/KJSenchaExample/tree/feature/component-generator

Component Generator Branch

This patch introduces a new feature where you can create Ext JS components on the PHP side, sometimes it's necessary to create complex windows which require a lot of server-side logic to create.

You can define server-side components in a ServiceManager like this:

    'components' => array(
        'invokables' => array(
            'Application.php.Window' => 'Application\ExtJs\Window'
        ),
        'factories' => array(
            'TestComponent' => function($sm) {
                return new Ext\Panel(array(
                    'title' => 'Test Component'
                ));
            }
        )
    ),

And then on the client-side you can load the windows with the Ext.ComponentLoader like this:

Ext.create('Ext.Window', {
    width: 800,
    height: 400,
    loader: {
        url : App.basePath + '/kjsencha/data/component',
        renderer: 'component',
        params: {
            className: 'Application.php.Window'
        },
        autoLoad: true
    }
}).show();

or

// Application.data == KJSencha.data.Factory
Ext.create('Ext.Window', {
    width: 800,
    height: 400,
    loader: Application.data.createCmpLoader('Application.php.Window')
}).show();

In a later patch the components can be added to the bootstrap so you can extend the dynamically defined ExtJS classes in your MVC application.

Simple example, this should be configurable in the bootstrap options later

$bootstrap->addComponent($componentManager->get('Application.php.Window'));
Ext.define('Application.view.Window', {
    extend: 'Application.php.Window'
});
Ocramius commented 11 years ago

Overall, this is a good one, but I don't really grasp the added feature (from my ExtJs ignorance). Is there some reference I could use to check what you are trying to achieve?

Rovak commented 11 years ago

@Ocramius, I've modified the description to explain the purpose of this PR

Ocramius commented 11 years ago

@Rovak thank you, that clarifies a lot!

Ocramius commented 11 years ago

@Rovak just a quick tip before thinking of merging this stuff... Let's write docs before merging, gets easier to handle on the long run ;)

Will get my stuff done by tomorrow: still confused by namespaces...

Rovak commented 11 years ago

Added examples in KJSenchaExample https://github.com/Rovak/KJSenchaExample/tree/feature/component-generator

Ocramius commented 11 years ago

If I get this correctly, you define (server side) components in a plugin manager, and then those get serialized into JS/JSON and served by a controller when the JS application requires them?

Rovak commented 11 years ago

Exactly, it enables you to generate highly flexible components like grids, trees and forms (Maybe even convert Zend\Form to an ExtJS form) on the server side, or generate windows which depend on server-side logic like ACL.

An example can be found in KJSenchaExample right here

Right now the functionality is kinda limited, but it provides a good base to expand on and maybe even surpass current frameworks like http://php-ext.quimera-solutions.com/ and https://github.com/indowebit/Ext-PHP