11

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

我正在寻找一个表单生成器,我发现了前者:

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 获得一个好的表单构建器库?

提前谢谢了

4

2 回答 2

0

你得到了 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

于 2015-04-22T10:55:06.127 回答
0

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>

它有效。

于 2015-05-20T04:17:35.637 回答