Luah的anahkiasen /前表单构建器库/(Laravel微框架)

时间:2015-04-22 10:40:08

标签: php laravel lumen

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

非常感谢提前

2 个答案:

答案 0 :(得分:0)

你是否得到了4.0分支,在Laravel 5 Illuminate \ Config \ Repository类中没有名为package的方法(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

答案 1 :(得分: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>

它有效。