【问题标题】:anahkiasen/former form builder lib for Lumen / (Laravel micro framework)anahkiasen / Lumen /(Laravel 微框架)的前表单构建器库
【发布时间】:2015-06-29 22:59:51
【问题描述】:

我正在使用 Laravel 最近新推出的微框架 Lumen。

我正在寻找一个表单生成器,我找到了Former:

http://anahkiasen.github.com/former/

我在一个简单的刀片视图中添加了以下代码:

use Former\Facades\Former;

echo Former::open()->method('GET');
    echo Former::text('name')->required();
echo Former::close();

我收到以下错误:

ErrorException in Container.php line 776:Class former does not exist (View: ...)

所以我将 ServiceProvider 添加到我的 app.php 中:

$app->register('Former\FormerServiceProvider');

我收到以下错误:

Fatal error: Call to undefined method Illuminate\Config\Repository::package() in D:\...\vendor\anahkiasen\former\src\Former\FormerServiceProvider.php on line 147

我的问题是:我怎样才能用 Lumen 完成它? 更糟糕的是,如何使用 Lumen 获得一个好的表单构建器库?

非常感谢提前

【问题讨论】:

    标签: php laravel lumen


    【解决方案1】:

    你得到 4.0 分支了吗,在 Laravel 5 Illuminate\Config\Repository 类中没有称为包的方法 (http://laravel.com/api/5.0/Illuminate/Config/Repository.html)

    由于 Lumen 使用Illuminate/config 5.0.*,您应该为表单生成器获得4.0 分支。 (https://github.com/formers/former#for-laravel-5-use-the-40-branch)

    【讨论】:

    • 是的,我没有使用 4.0 分支。我已经成功了。现在我使用的是 4.0,但出现以下错误: Container.php 第 776 行中的 ReflectionException:Class path.config 不存在
    【解决方案2】:

    这个composer.json 配置似乎在我的应用程序中有效。

    "repositories": [
        {
            "type": "git",
            "url": "https://github.com/formers/former.git"
        }
    ],
    "require": {
        "laravel/lumen-framework": "5.0.*",
        "vlucas/phpdotenv": "~1.0",
        "anahkiasen/former": "4.0.x-dev"
    },
    

    做完之后:

    composer update -vvv
    

    我更新了我的bootstrap/app.php:

    /*
    |--------------------------------------------------------------------------
    | Register Service Providers
    |--------------------------------------------------------------------------
    |
    | Here we will register all of the application's service providers which
    | are used to bind services into the container. Service providers are
    | totally optional, so you are not required to uncomment this line.
    |
    */
    
    // $app->register('App\Providers\AppServiceProvider');
    $app->register('Former\FormerServiceProvider');
    

    在app/Http/routes.php中测试:

    /*
    |--------------------------------------------------------------------------
    | Application Routes
    |--------------------------------------------------------------------------
    |
    | Here is where you can register all of the routes for an application.
    | It's a breeze. Simply tell Laravel the URIs it should respond to
    | and give it the controller to call when that URI is requested.
    |
    */
    use Former\Facades\Former;
    
    $app->get('/', function() use ($app) {
        echo Former::open()->method('GET');
            echo Former::text('name')->required();
        echo Former::close();
    });
    

    输出:

    <form accept-charset="utf-8" class="form-horizontal" method="GET">
        <div class="form-group required">
            <label for="name" class="control-label col-lg-2 col-sm-4">Name<sup>*</sup></label>
            <div class="col-lg-10 col-sm-8">
                <input class="form-control" required="true" id="name" type="text" name="name">
            </div>
        </div>
    </form>
    

    一切似乎都很好。我认为问题出在过时的软件包上。

    更新

    我把我的app/Http/routes.php 改成这样的:

    $app->get('/', function() use ($app) {
        return view('foo');
    });
    

    这是我的foo.blade.php:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Foo</title>
    </head>
    <body>
        {!! Former\Facades\Former::open()->method('GET'); !!}
            {!! Former\Facades\Former::text('name')->required(); !!}
        {!! Former\Facades\Former::close(); !!}
    </body>
    </html>
    

    而且它有效。

    【讨论】:

      猜你喜欢
      • 2016-04-07
      • 2018-06-03
      • 1970-01-01
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多