PHP code example of gridphp / ci4-starter

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

    

gridphp / ci4-starter example snippets


namespace App\Controllers;

class Home extends BaseController
{
    public function index(): string
    {
        // Initialize GridPHP with CI4 database config
        $g = new \jqgrid(config('GridPHP')->dbconf());

        // Set table name
        $g->table = 'customers';

        // Render grid HTML and JavaScript snippet
        $data['output'] = $g->render('my_first_grid');

        // Pass output to view
        return view('hello_grid', $data);
    }
}

namespace App\Controllers;

class Home extends BaseController
{
    // Master Grid Page
    public function index(): string
    {
        $g = new \jqgrid(config('GridPHP')->dbconf());

        // Configure Master Grid Options
        $g->set_options([
            'caption'     => 'Customer Directory (Master)',
            'multiselect' => true,
            'subGrid'     => true,
            'subgridurl'  => 'detail', // Subgrid AJAX endpoint
        ]);

        $g->table = 'customers';
        $g->select_command = 'SELECT customer_id, company_name, contact_name, city, country FROM customers';

        // Column Formatters
        $g->set_columns([
            ['name' => 'country', 'formatter' => 'badge'],
            ['name' => 'city',    'formatter' => 'badge'],
        ], true);

        // Actions: Export, Edit, Delete
        $g->set_actions([
            'export' => true,
            'add'    => true,
            'edit'   => true,
            'delete' => true,
        ]);

        $data['output'] = $g->render('master_customers');

        return view('welcome_message', $data);
    }

    // Detail Subgrid Endpoint (AJAX payload)
    public function detail(): string
    {
        $g = new \jqgrid(config('GridPHP')->dbconf());

        $g->set_options([
            'caption'  => '',
            'readonly' => true,
            'toolbar'  => 'bottom',
        ]);

        $g->table = 'orders';

        // Filter detail records by rowid passed from parent row
        $customerId = $this->request->getGet('rowid') ?? '';
        $g->select_command = "SELECT order_id, order_date, shipped_date, freight, ship_name FROM orders WHERE customer_id = '{$customerId}'";

        // Return raw rendered subgrid for AJAX injection
        return $g->render('detail_orders');
    }
}

// for fetching data
$routes->get('/', 'Home::index');
$routes->get('detail', 'Home::detail');

// for CRUD operations
$routes->post('/', 'Home::index');
$routes->post('detail', 'Home::detail');
bash
   php spark serve