PHP code example of swoopaholic / components

1. Go to this page and download the library: Download swoopaholic/components library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

swoopaholic / components example snippets

 php
...
use Swoopaholic\Component\Table\Extension\DependencyInjection\Compiler\TablePass;
use Swoopaholic\Component\Table\Extension\DependencyInjection\Compiler\TableTemplatePass;
...
public function build(ContainerBuilder $container)
{
    $container->addCompilerPass(new TablePass());
    $container->addCompilerPass(new TableTemplatePass());
}
 php

namespace Namespace\Bundle\MyBundle\CrudTable;

use Swoopaholic\Component\Table\Extension\Crud\Type\TableType;
use Swoopaholic\Component\Table\TableBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends TableType
{
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        parent::setDefaultOptions($resolver);
        $resolver->setRequired(array('data'));
    }

    public function buildTable(TableBuilderInterface $builder, array $options)
    {
        $this
            ->addColumn('username', 'text', array('label' => 'Naam', 'sort' => 'username'))
            ->addColumn('email', 'text', array('label' => 'E-mail', 'sort' => 'email'))
            ->addColumn('enabled', 'text', array('label' => 'Enabled'))
            ->addColumn('last_login', 'datetime', array('label' => 'Ingelogd op', 'sort' => 'lastLogin'));

        parent::buildTable($builder, $options);
    }

    public function buildRowActions($builder, $cell, $item, array $options)
    {
        $group = $builder->create('group', 'crud_action_group', array());
        $group->add('show', 'crud_action', array(
            'icon' => 'eye-open',
            'url' => $this->router->generate('nvs_framework_user_show', array('id' => $item->getId())),
            'label' => 'Bekijken',
            'attr' => array('data-rowclick' => '')
        ));

        $group->add('edit', 'crud_action', array(
            'icon' => 'eye-open',
            'url' => $this->router->generate('nvs_framework_user_edit', array('id' => $item->getId())),
            'label' => 'Bewerken',
            'attr' => array('data-rowclick' => '')
        ));

        $cell->add($group);
    }

    public function getParent()
    {
        return 'table';
    }

    public function getName()
    {
        return 'user';
    }
}
 php
$data = $this->getData()
$tableFactory = $this->get('table.factory');

$table = $tableFactory->create(
    'user',
    $data,
    array('table_route' => $route, 'responsive' => true)
);