1. #81
    Sencha User khebs@live.com's Avatar
    Join Date
    Mar 2008
    Posts
    83
    Vote Rating
    0
    khebs@live.com is on a distinguished road

      0  

    Default


    Hi Mate, been so long can you make a laravel bundle for this? please

  2. #82
    Ext JS Premium Member
    Join Date
    Sep 2010
    Posts
    370
    Vote Rating
    6
    stewardsencha is on a distinguished road

      0  

    Default


    1. Create folder laravel/bundles

    2. Copy Bruni's ExtDirect.php into that folder

    3. Create laravel/bundles/direct/start.php:

    Code:
    require_once(Bundle::path('direct').'ExtDirect.php'); // J Bruni
    4. Add it to your application/bundles.php

    Code:
    return array(
        'direct'=>array('handles'=>'direct')
    );
    Start routing to your direct bundle !

    In other words, there's nothing for Bruni to do. His work is awesome.
    Just follow the simple recipe at laravel for creating bundles. Ask for help at that site.
    Or don't bother. It's just as easy to use as a library.

    You have to read his code. Everything is there. But it will need to be tweaked for your situation.

    His controller does not return to the laravel core, he simply spits out the results when ready.

    Laravel dudes would frown. Whether you need to take that further depends again on your situation.

    But you know what? I am finding ExtDirect is sucking away my life for no fun.

    It creates challenges in the build and with using SA. It is always wanting extra attention for this or that.

    For me, it has slowed progress considerably, and I regret using it.

    Just look at all of bruni's code (which is now your own to understand and manage).

    You'll need to discover how to use it with SA. Thats sucks away a bit.

    And getting it right (do not try to execute before Ext is loaded, delaying creation of stores until provider is ready) may be no brainer for the experienced dudes, but it tripped me many times.

    And for what exactly? Know your use cases and motivation. Plan on extra delays for ExtDirect.

    Here (was) my laravel/bundles/direct/routes.php as I built the examples.
    This was Day One code, I have since moved on...

    Code:
    ///////////////////////////////////////////////////////////////////////////
    /*
     * These first two routes implement JBruni's simple example.
     *
     * site.com/direct/example            (JBruni would have used site.com/example.php, we drop the php extension)
     * site.com/direct/example.html       (You need to edit direct/example.html to point to your ext install)
     */
    Route::any('direct/example',function() {
        class Server
        {
            public function date( $format )
            {
                return date( $format );
            }
        }
        ExtDirect::$url=URL::to('direct/example');
        ExtDirect::provide( 'Server' ); // poof our Server class is available to javascript
    });
    
    Route::get('direct/example.html',function(){
        return Response::make(file_get_contents(Bundle::path('direct').'example.html'));
    });
    
    /*
     *  Hmm. Now we need a page for the extjs samples.
     *
     *  ExtAsset::sample takes an ordered list of scripts to add to direct/view/sample.php
     *  That should give us a shell to test a couple of the ExtDirect sampless
     */
    
    /////////////////////////////////////
    Route::any('direct/test',function() {
        ExtDirect::$url=URL::to('direct/test');
        ExtDirect::provide( 'TestAction' );
    });
    Route::any('direct/test.html',function() {
        ExtDirect::$url=URL::to('direct/test');
        ExtAsset::sample(array('direct/test?javascript','apps/direct/test.js'));
        return View::make('direct::sample')->with('title', 'test');
    });
    
    
    /////////////////////////////////////////
    // Service the polling demo. No class.
    Route::get('(:bundle)/poll', function() {
    
        $result=array(
            'type'=>'event',
            'name'=>'message',
            'data'=>'Successfully polled at: '. date('g:i:s a')
        );
        return new Response(json_encode($result),200, array('Content-Type'=>'application/json'));
    });
    Route::any('direct/poll.html',function() {
        ExtDirect::$url=URL::to('direct/poll');
        ExtAsset::sample(array('apps/direct/poll.js'));
        return View::make('direct::sample')->with('title', 'poll');
    });
    
    // Now we have a pattern, follow it for the other samples: grid, tree and named-arguments...
    Route::any('direct/tree',function() {
        IoC::resolve('TestAction');
        ExtDirect::$url=URL::to('direct/tree');
        ExtDirect::provide( 'TestAction' );
    });
    Route::any('direct/tree.html',function() {
        ExtDirect::$url=URL::to('direct/tree');
        ExtAsset::sample(array('direct/tree?javascript','apps/direct/direct-tree.js'));
        return View::make('direct::sample')->with('title', 'tree');
    });
    //
    Route::any('direct/grid',function() {
        IoC::resolve('TestAction');
        ExtDirect::$url=URL::to('direct/grid');
        ExtDirect::provide( 'TestAction' );
    });
    Route::any('direct/grid.html',function() {
        ExtDirect::$url=URL::to('direct/grid');
        ExtAsset::sample(array('direct/grid?javascript','apps/direct/direct-grid.js'));
        return View::make('direct::sample')->with('title', 'grid');
    });
    //
    Route::any('direct/named-arguments',function() {
        ExtDirect::$url=URL::to('direct/named-arguments');
        ExtDirect::provide( 'TestAction' );
    });
    Route::any('direct/named-arguments.html',function() {
        ExtDirect::$url=URL::to('direct/named-arguments');
        ExtAsset::sample(array('direct/named-arguments?javascript','apps/direct/named-arguments.js'));
        return View::make('direct::sample')->with('title', 'named-arguments');
    });
    If I had to do this again:
    - I would not bother making ExtDirect a bundle. Just drop it in your library and use it.
    - I would not use ExtDirect without a serious motivation

    Good luck.

    And many thanks to J Bruni.

  3. #83
    Sencha User khebs@live.com's Avatar
    Join Date
    Mar 2008
    Posts
    83
    Vote Rating
    0
    khebs@live.com is on a distinguished road

      0  

    Default


    Hi Thanks for the detailed explanations this is actually a debate to my self that i would just use simple api for this.. but ill try around see what fits..

  4. #84
    Sencha User
    Join Date
    Nov 2010
    Posts
    13
    Vote Rating
    1
    Kynao is on a distinguished road

      0  

    Default


    Hello,

    there is no simple way or documentation to use it with sencha architect ?
    what alternative to ext.direct for using extjs with laravel along a simple approach ?

  5. #85
    Ext JS Premium Member
    Join Date
    Sep 2010
    Posts
    370
    Vote Rating
    6
    stewardsencha is on a distinguished road

      0  

    Default


    Like I say, I have moved on, but this is what worked for me at the time:
    Code:
    // There are supposed to be formats attached to the request, eg ?xml ?json.
    // Thought ExtDirect handled it and thought I saw it working once. But this is okay for now.
    Route::any('direct/video, direct/arkvideo', function() {
    
        try{
            // Laravel has sexier ways to do this I am sure.
            if (strstr(URI::current(),'ark'))
            {
                // Request is coming from the Sencha Architect (ark ark)
                ExtDirect::$default_api_output = 'json';
            }
            else
            {
                // Service for ext apps
                ExtDirect::$default_api_output = 'javascript';
            }
    In other words, I gave SA a slightly different url for ExtDirect, so laravel could notice and set the output format accordingly.

    Cheesy but easy.

  6. #86
    Sencha User
    Join Date
    Nov 2010
    Posts
    13
    Vote Rating
    1
    Kynao is on a distinguished road

      0  

    Default


    Thanks you stewardsencha

  7. #87
    Sencha User
    Join Date
    Nov 2010
    Posts
    13
    Vote Rating
    1
    Kynao is on a distinguished road

      0  

    Default


    Quote Originally Posted by stewardsencha View Post
    Like I say, I have moved on
    By the way, you moved on what ?
    About "You'll need to discover how to use it with SA". Did someone expose the created challenges in the build and with using SA ? and discovered a solution how to deal with it.

  8. #88
    Sencha User j.bruni's Avatar
    Join Date
    Jun 2009
    Location
    Uberlândia, MG, Brazil
    Posts
    105
    Vote Rating
    7
    j.bruni is on a distinguished road

      1  

    Default JSON x JavaScript output

    JSON x JavaScript output


    This ExtDirect class does provide a shortcut to select between JSON or JavaScript output, which is to provide a "javascript" parameter in the query string of the requested URL. For example:

    http://domain.com/direct/example - this outputs JSON

    http://domain.com/direct/example?javascript - this outputs JavaScript

    This is performed at ExtDirectController::get_api method, as seen below:

    PHP Code:
        /**
         * @return string   JSON or JavaScript API declaration for the classes on "api_classes" configuration array
         */
        
    public function get_api()
        {
            if ( isset( 
    $_GET['javascript'] ) || ( ExtDirect::$default_api_output == 'javascript' ) )
                return 
    ExtDirect::get_api_javascript();
            else
                return 
    ExtDirect::get_api_json();
        } 
    The "core" of it is the isset( $_GET['javascript'] ) snippet.

  9. #89
    Sencha User
    Join Date
    Nov 2010
    Posts
    13
    Vote Rating
    1
    Kynao is on a distinguished road

      0  

    Default


    Thanks again j.bruni

  10. #90
    Sencha User
    Join Date
    Oct 2012
    Posts
    3
    Vote Rating
    0
    cbj4074 is on a distinguished road

      0  

    Default


    Quote Originally Posted by AndreKR View Post
    What do I need to set count_only_required_params to, so that optional parameters are optional?
    I am wondering the same thing, and if the response that follows is still relevant.

    Quote Originally Posted by j.bruni View Post
    ...
    Finally, @AndreKR...

    This post (http://www.sencha.com/forum/showthre...l=1#post480214) teaches how apply configurations (I know you read it, I am linking for the others...)

    All configurations must come before the "ExtDirect::provide" call:

    PHP Code:
    ExtDirect::$configuration_name $value
    In your case, you want to perform the following configuration:

    PHP Code:
    ExtDirect::$count_only_required_params true
    This will make the "len" property of the respective API declaration correspond to the number of required parameters. So, for a PHP method declared like this...

    PHP Code:
    function calculate_something$needed$optional 
    ...the "len" value will be "1", instead of "2".

    And this is all.

    Now, ExtJS requires you to make the remote function call with the number of parameters declared in the "len" property. In other words: there is no such things as "optional parameters" in the client-side, because of the way ExtJS Direct is designed.

    In the example, you need to choose: it will be either "1" or "2" parameters. You simply can't choose "1" and optionally "2", at the ExtJS side. Makes sense?
    I am using the sample descriptor code (for PHP) that is provided with the Ext Direct Pack and the mechanism for setting default configuration values seems to have changed:

    PHP Code:
    $api = new ExtDirect_API();

    $api->setRouterUrl('router.php'); // default
    $api->setCacheProvider($cache);
    $api->setNamespace('Ext.ss');
    $api->setDescriptor('Ext.ss.APIDesc');
    $api->setDefaults(array(
        
    'autoInclude' => true,
        
    'basePath' => 'classes'
    )); 
    Regarding ExtJS Direct configuration, in general, I am wondering if these configuration directives are still relevant:

    Quote Originally Posted by j.bruni View Post
    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 <script> tag that refers to your API
    example
    PHP Code:
    ExtDirect::$default_api_output "javascript"
    Does current (ExtJS 4+), formal documentation of these directives exist? If so, might anyone be able to provide a URL? I have looked and came-up empty.

    Thanks in advance.