定制 lucasromanojf/ext-direct 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lucasromanojf/ext-direct

Composer 安装命令:

composer require lucasromanojf/ext-direct

包简介

Laravel ExtJS/Sencha direct provider

README 文档

README

##Info This is ext-direct provider for laravel 4.x (works with extjs 5 as well)

The idea behind ext-direct is to allow javascript to call remote php methods as they were client side javascript methods. This is reducing dramatically the development time.

Heavily(almost 99%) based on http://www.sencha.com/forum/showthread.php?102357-Extremely-Easy-Ext.Direct-integration-with-PHP

The original class was touched just a little bit.

##Installation##

Add this line to the composer.json require list and run composer update

"bulforce/ext-direct": "dev-master"

Add to app.php 'providers' array:

'Bulforce\ExtDirect\ExtDirectServiceProvider', 

This package comes with a Facade but you dont have to include it in your app.php it is automatically included.

You MUST publish or create this config file:

../laravel_project/app/config/packages/bulforce/ext-direct/config.php

You MUST edit the config.php file:

<?php

return array(
    'namespace' => 'Ext.rpc',
    'descriptor' => 'Ext.rpc.REMOTING_API',
    'timeout' => 30,
    'debug' => true,
    'api_classes' => array(
        'Items' => 'ItemsController'
    )
);

Most important part is the api_classes array, there you have to list all the classes(normally controllers) from your application that you want to make availabe to extjs to call directly.

Note that it doesnt have to be associative array, you can simply list the class name in a normal indexed array. However if you list them as associative array then you can call them from extjs using the array element key instead of the actuall controller class name. This way you can hide your real application structure from the front end.

TAG Direct methods In order for a controller method to be made available to extjs/sencha to call directly two conditions must be met:

1. Method needs to be declared as **public**
2. Method needs to contain comment tag @direct

example:

    /**
     * @direct
     */
    public function read($params = null) {
        return Item::take(50)->get();
    }

add a route in your routes.php

    Route::any('/rpc', function() {
        return ExtDirect::provide();
    });

Lastly add something like this in your index.html (after extjs library and before your application code!!!)

<script type="text/javascript" src="http://laravel_project.dev/rpc?javascript"></script>

Now you should be able to call laravel controller methods from javascript directly

Ext.rpc.Items.read(function(response) {
    console.log(response);
});

//with params, params will be passed to the controller method as php object
Ext.rpc.Items.read({page: 5},function(response) {
    console.log(response);
});

//use it in direct stores api object
api: {
    read: Ext.rpc.Items.read
}

统计信息

  • 总下载量: 35
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 13
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固