此包的最新版本(v0.91)没有可用的许可信息。

v0.91 2015-09-05 22:44 UTC

This package is not auto-updated.

Last update: 2024-09-15 00:36:55 UTC


README

Laravel 4.2 的表格构建器

###安装

{
    "require": {
        "mobytes/htmlext": "dev-master"
    }
}

运行 composer update

然后在 config/app.php 中添加服务提供者

    'providers' => [
        // ...
        'Mobytes\Htmlext\HtmlextServiceProvider'
    ]

以及外观(也在 config/app.php 中)

    'aliases' => [
        // ...
        'TableBuilder'	  => 'Mobytes\Htmlext\Facade\TableBuilder',
    ]

快速开始

创建一个带有表格设置的类

<?php namespace App\Tables;

use Mobytes\Htmlext\Table;

class NoticeTable extends Table
{
    //create text button
    protected $btn_new = "Crear nueva noticia";
    
    //Table title 
    protected $title = "Todas las noticias de cepco.org.pe";
    
    //activate the paginate
    protected $paginate = true;
    
    //number of records per page
    protected $per_page = 7;
    
    //Titles of thead
    protected $thead = array(
        "title" => [
            "Titulo",
            "Subtitulo",
            "Contenido",
            "Tags",
            "Actions"
        ]
    );
    
    //records tbody
    protected $tbody = array(
        "fields" => [
            "titulo" => [
                "class" => ""
            ],
            "subtitulo" => [
                "class" => ""
            ],
            "contenido" => [
                "class" => ""
            ],
            "tags" => [
                "class" => ""
            ]
        ]
     );
    
    //Start function    
    public function build()
    {
        $prefix_router = "landpage.noticias";
        $this->build($prefix_router);
    }
}

然后,在控制器中实例化该类并将其传递到视图中

<?php namespace App/Http/Controllers;

use Illuminate\Routing\Controller as BaseController;
use Mobytes\Htmlext\TableBuilderTrait;

class NoticesController extends BaseController {
    
    // ...
    use TableBuilderTrait;
    
    public function index()
    {
        //notices type Builder
        $notices = $this->publication->getAllByType(self::$_NOTICE);
        
        $table = $this->table('Mobytes\Landpage\Publication\Table\NoticeTable',$notices);
        
        return View::make(Config::get('notices.index'), compact('table'));
    }
}

使用 table() 辅助函数在视图中打印表单

<!-- views/notices/index.blade.php -->

@extend('layouts.master')

@section('content')
    {{ table($table) }}
@endsection