<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>A Basic PHP Datagrid</title>
</head>
<body>


<h1>Your first grid</h1>

<h3>Where to keep phpGrid files in Symfony</h3>

This is a very common question (Hint: not inside "vendor" folder). The short answer is "web" folder. Symfony web assets are used to keep things like CSS, JavaScript and image files that renders the frontend of your site. Store your phpGrid library in the web/ directory.

<h3>Edit conf.php in phpGrid</h3>

Remember to change the database credentials in conf.php. You do not need to set SERVER_ROOT value because phpGrid is inside public accessible "web" folder. 

<h3>Enable PHP templating engine</h3>

Before we start phpGrid Symfony integration, make sure the "php" templating engine is enabled in your application configuration file under app/config .Symfony defaults to Twig for its template engine, but you can still use plain PHP code if you want. Symfony adds some nice features on top of PHP to make writing templates with PHP more powerful. 

[cc lang="php"]
# app/config/config.yml
framework:
    # ...
    templating:
        engines: ['twig', 'php']
[/cc]


<h3>Create Symfony Controller</h3>

Symfony Controller needs to call our grid view file because we do not want to use Controller to render our datagrid. In this demo, we will modify the default controller located in folder "src/AppBundle/Controller/"
        
[cc lang="php"]
...
return $this->render('phpgrid/simple.html.php');
...
[/cc]

<h3>Create Symfony View file</h3>

First of all, create a new folder named "phpgrid" in "app/Resources/views". Secondly, create a view file named "simple.html.php", or whatever view file name used in Controller in the previous step.

Include the phpGrid config file.

[cc lang="php"]
$vendorDir = $this->container->getParameter('kernel.root_dir');
require_once($vendorDir ."/../web/phpGrid_Lite/conf.php");
[/cc]

Load a simple datagrid from database table "orders"

[cc lang="php"]
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->display();
[/cc]

Congrats! You just created your first datagrid in Symfony. Now visit "your_domain.com/phpgrid/simple" to see the datagrid.  

<?php
// include phpGrid config file
$vendorDir = $this->container->getParameter('kernel.root_dir');
require_once($vendorDir ."/../web/phpGrid_Lite/conf.php");

// Load a simple datagrid from database table "orders"
$dg = new C_DataGrid("SELECT * FROM orders", "orderNumber", "orders");
$dg->display();
?>

</body>
</html>