PHP code example of netsells / exportable

1. Go to this page and download the library: Download netsells/exportable 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/ */

    

netsells / exportable example snippets


  $users = User::all()->toArray();
  $headers = [
      "first_name"    => "First Name",
      "last_name"     => "Last Name",
      "email"         => "Email",
      "phone"         => "Phone",
  ];

  $view = "exportable\\pdf";
  User::exportToPdf($view, $users, $headers);

  $users = User::all()->toArray();
  $headers = [
      "first_name"    => "First Name",
      "last_name"     => "Last Name",
      "email"         => "Email",
      "phone"         => "Phone",
  ];

  User::exportToCsv($users, $headers);

  return [
    'pdf' => [
        'headers' => [
            // Map headers for PDF export here
        ],
        // View used to construct PDF export
        'view' => 'exportable\pdf',
    ],
    'csv' => [
        'headers' => [
            // Map headers for CSV export here
        ],
    ]
  ];

  return [
    'user' => [
      'pdf' => [
          'headers' => [
            "first_name"    => "First Name",
            "last_name"     => "Last Name",
            "email"         => "Email",
            "phone"         => "Phone",
            "email"         => "Email",
          ],
          // View used to construct PDF export
          'view' => 'exportable\user_pdf',
      ],
    ],
    'admin' => [
      'pdf' => [
          'headers' => [
            "first_name"    => "First Name",
            "last_name"     => "Last Name",
            "email"         => "Email",
            "phone"         => "Phone",
            "email"         => "Email",
            "permission_level" => "Permissions",
          ],
          // View used to construct PDF export
          'view' => 'exportable\admin_pdf',
      ],
    ]  
  ];

  class User extends ExportableModel
  {
      const ADMIN_PDF_CONFIG = 'exportable.admin.pdf';
      const USER_PDF_CONFIG = 'exportable.user.pdf';

  // Confirm class constant defined
  if ($configPath = User::getConstant('ADMIN_PDF_CONFIG')) {
      $config = Config::get($configPath);
      $headers = $config['headers'];
      $view = $config['view'];
      $users = User::all()->toArray();
      User::exportToPdf($view, $data, $headers);
  }