Installation Guide

There are 2 ways to install grocery CRUD Enterprise to your project:
1. Without Composer (recommended for people that are not using PHP frameworks and/or composer)
2. Composer (recommended for PHP frameworks like Laravel,… e.t.c.)

If you are looking for more specific installation guidance, you can also check the below tutorials:
1. Installation in Codeigniter
2. Laravel installation

Installation

1. Without Composer

For many people composer seems too complicated and they prefer the old fashioned copy-paste way. Also if you are using a framework that it is not requiring composer or you are using native PHP then the installation without composer is the best choice. There is nothing bad with the installation without composer, it is just that on updates it will require more manual work.

In case you prefer a video tutorial, we did create the below steps into a video see: Grocery CRUD Enterprise – Installation without composer

Step 1.

Download the zip file for installation without composer. You can also download the newest zip file from: https://www.grocerycrud.com/users . In order to have a a more specific example from now on we will use the name:  grocery-crud-enterprise-v2.0.1.zip as the zip file

Step2.

Unzip the file and you will find a file structure like that:

├── examples
│   ├── config.php
│   ├── database.php
│   ├── example.php
│   └── view.php
├── libraries
│   ├── autoload.php
│   ├── bin
│   ├── composer
│   ├── ...
│   ├── phpunit
│   ├── symfony
│   └── zendframework
└── public
    └── grocery-crud
        ├── css
        ├── fonts
        ├── images
        └── js

The folders have the following files:
1. examples folder has a very basic example so you can simply copy the files and see it working on native PHP.
2. libraries folder has all the PHP libraries that are required in order groceryCRUD to run. This is basically the folder vendor from composer just renamed to not have conflicts in case you want to use composer on other purposes
3. public folder is the one that has all the JS,CSS, fonts and images that are required in order to show it on a webpage. The name is public as these files are the one that will be visible from a web browser

Before going to the next step there are 2 config files that you are required to configure. The first one is the database connection credentials. A simple database file like the below is required:

//database.php
<?php
return [
    'adapter' => [
        'driver' => 'Pdo_Mysql',
        'database' => 'db_name',
        'username' => 'db_username',
        'password' => 'db_password',
        'charset' => 'utf8'
    ]
];

As in grocery CRUD Enterprise we are using the power of Zend Framework the drivers are from Zend Framework DB version 2. For more you can see the documentation at Zend\Db\Adapter

The second configuration file is the one that you need to include for grocery CRUD. The configuration file will look like the below:

//config.php
<?php
return [
    // So far 34 languages including: Afrikaans, Arabic, Bengali, Bulgarian, Catalan, Chinese, Czech, Danish,
    // Dutch, English, French, German, Greek, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean,
    // Lithuanian, Mongolian, Norwegian, Persian, Polish, Portuguese, Brazilian Portuguese, Romanian,
    // Russian, Slovak, Spanish, Thai, Turkish, Ukrainian, Vietnamese
    'default_language'	=> 'English',

    // This is the assets folder where all the JavaScript, CSS, images and font files are located
    'assets_folder' => '/assets/grocery-crud/',

    // There are only three choices: "uk-date" (dd/mm/yyyy), "us-date" (mm/dd/yyyy) or "sql-date" (yyyy-mm-dd)
    'date_format' => 'uk-date',

    // The default per page when a user firstly see a list page
    'default_per_page'	=> 10,

    // Having some options at the list paging. This is the default one that all the websites are using.
    // Make sure that the number of grocery_crud_default_per_page variable is included to this array.
    'paging_options' => ['10', '25', '50', '100'],

    // The environment is important so we can have specific configurations for specific environments
    'environment' => 'development',

    // This is basically in order to have a php cache. Be aware that in case you disble the php cache
    // things will get too slow
    'backend_cache' => false,

    'xss_clean' => false,

    // The character limiter at the datagrid columns, zero(0) value if you don't want any character
    // limitation to the column
    'column_character_limiter' => 50,

    // For more read http://framework.zend.com/manual/current/en/modules/zend.cache.storage.adapter.html
    // If you are not sure about how to use it, you can just change the ttl value (time to live) and
    // the file path of the cache
    'cache' => [
        'adapter' => [
            'name'    => 'filesystem',
            'options' => [
                'namespace' => 'gcrud',
                'ttl' => 3600 * 24 * 30 * 6,
                'cache_dir' => realpath(__DIR__ . '/Cache/')
            ],
        ],
        'plugins' => [
            'exception_handler' => ['throw_exceptions' => false],
        ],
    ],
];

At the config file there are 3 basic sections that we need to be aware of:

  1. The assets_folder:  The assets folder is the folder that can publicly be accessible by the end user. These folders includes: images, JavaScript files, fonts and stylesheets files.
  2. The environment: Make sure that the development environment is the one that you are using when you are developing the project. and production is the one that is used when you are publishing the website to production.
  3. The cache: Grocery CRUD is based on cache to do as less queries to the database as possible it is strongly advised to use cache to your project. The default cache is the files cache but of course you can change the cache configurations to add a faster method to cache. All the configurations for the cache can be found at:  Zend\Cache\Storage\Adapter

Step3.

If you are using native PHP (without any framework) then you just need to copy the examples at the desired folder.

As it is always better to have a real example. Let’s say that you have a PHP project that has the below structure (usually when people are using native PHP they don’t use routes and hence the following structure).

├── assets
├── libs
├── index.php
├── customers.php
└── films.php

and all the JavaScript and CSS files are in the assets folder.

Copy the config files: config.php, database.php, example.php, view.php at your app folder.

So now your folder will look like this:

├── assets
├── libs
├── index.php
├── config.php
├── database.php
├── example.php
├── view.php
├── customers.php
└── films.php

And the example.php looks like this:


&lt?php

include("../libraries/autoload.php");

use GroceryCrud\Core\GroceryCrud;

$database = include('database.php');
$config = include('config.php');

$crud = new GroceryCrud($config, $database);

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
//$crud->columns(['customerName', 'contactLastName', 'contactFirstName']);

$output = $crud->render();

if ($output->isJSONResponse) {
    header('Content-Type: application/json; charset=utf-8');
    echo $output->output;
    exit;
}

$css_files = $output->css_files;
$js_files = $output->js_files;
$output = $output->output;

include('view.php');

So now we will basically change just slightly the example.php to fit to our needs for the films.php. So first of all let’s assume that the films.php has some code of your own project. For that reason, I will include the ... at the below example so you can understand that this is basically your code (e.g. header, footer, some functionality… e.t.c.).

So the final example for films.php will look like this:

&lt?php
// We are adding everything at the top for includes... e.t.c.
include("libraries/autoload.php");

use GroceryCrud\Core\GroceryCrud;

// Your code
...

$database = include('database.php');
$config = include('config.php');

$crud = new GroceryCrud($config, $database);

$crud->setTable('films');
$crud->setSubject('Film', 'Films');

$output = $crud->render();

if ($output->isJSONResponse) {
    header('Content-Type: application/json; charset=utf-8');
    echo $output->output;
    exit;
}

$css_files = $output->css_files;
$js_files = $output->js_files;
$output = $output->output;

// The below include is not required. If you have another way to show:
// a. the output
// b. the CSS and JS files
// Then you can basically include the results of the output and the CSS/JS files to your own framework's output or template
include('view.php');

// Your code
...

Now from the above code you will have a full working CRUD without the need to do anything else! You can now enjoy all the power of Grocery CRUD at the documentation (and you didn’t use any terminal at all).

2. Installation with composer

If you prefer the video tutorials well… we did create a video tutorial with all the below information into one video.

The most recommended way to install PHP libraries nowadays is through composer. Grocery CRUD Enterprise has private code and you should have one more step from the normal composer installations. This extra step will change at the future however this work is still in progress and currently you will need to do these 2 extra steps.
Step 1. 
Download the version of groceryCRUD Enterpirse from https://www.grocerycrud.com/users or through the email that you did get. For example the file to download is: grocery-crud-enterprise-v2.0.0.zip

Step 2.

store this file through a folder that you are adding your libraries. This can be anywhere at your local environment however it is important to not rename the zip file. As this file is an artifact, we will name our folder artifacts/ you can of course use your own names like lib/ or even more specific groceryCRUD/ if you are going to use artifacts only for groceryCRUD

Step 3.

Add the below code at your composer.json

{
    "repositories": [
        {
            "type": "artifact",
            "url": "/path/to/artifacts/"
        }
    ],
    "require": {
        "grocerycrud/enterprise": "version-number"
    }
}

For example (a project that will have only groceryCRUD Enterprise as third party libraries):

{
    "repositories": [
        {
            "type": "artifact",
            "url": "artifacts/"
        }
    ],
    "require": {
        "grocerycrud/enterprise": "2.*.*"
    }
}

As many people are new to composer and sometimes is really annoying to not have real examples, I will give a more specific example of how your composer will look like. So let’s say that you have installed laravel to your project. Your composer.json will look something like this (see with bold the new lines):

{
	"name": "laravel/laravel",
	"description": "The Laravel Framework.",
	"keywords": ["framework", "laravel"],
	"license": "MIT",
	"type": "project",
"repositories": [
            {
                "type": "artifact",
                "url": "artifacts/"
            }
        ]
	"require": {
		"laravel/framework": "5.0.*",
"grocerycrud/enterprise": "2.*.*"
	},
	"require-dev": {
		"phpunit/phpunit": "~4.0",
		"phpspec/phpspec": "~2.1"
	},
	"autoload": {
		"classmap": [
			"database"
		],
		"psr-4": {
			"App\\": "app/"
		}
	},
	"autoload-dev": {
		"classmap": [
			"tests/TestCase.php"
		]
	},
	"scripts": {
		"post-install-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-update-cmd": [
			"php artisan clear-compiled",
			"php artisan optimize"
		],
		"post-create-project-cmd": [
			"php -r \"copy('.env.example', '.env');\"",
			"php artisan key:generate"
		]
	},
	"config": {
		"preferred-install": "dist"
	},
}

Step 4.
Now just run composer update or composer install if you are running composer for the first time on your project. Now you did install the enterprise version to your project. You will need also to copy the assets and add it to your public folder for all the JavaScript,CSS, fonts… e.t.c.

Step 5.
In order to install all your assets to your project. You need to manually copy  the folder public to your public structured project.

To have a more specific example. So let’s say that you are using laravel and the structure looks like this:

├── app
│   ├── Commands
│   ├── Console
│   ├── Events
│   ├── Exceptions
│   ├── Handlers
│   ├── Http
│   ├── Providers
│   └── Services
├── bootstrap
├── config
├── database
│   ├── migrations
│   └── seeds
├── public
│   ├── css
│   └── fonts
├── resources
│   ├── assets
│   ├── lang
│   └── views
├── storage
│   ├── app
│   ├── framework
│   └── logs
├── tests
└── vendor

In that case the best place to have your public folder of groceryCRUD enterprise is at pubic->grocery-crud folder. So you will need to copy the folder from : vendor/grocerycrud/enterprise/public/grocery-crud/ to the public folder of laravel
So after the copy your folder structure will look like this (in bold you can find the changed ones)

├── app
│   ├── Commands
│   ├── Console
│   ├── Events
│   ├── Exceptions
│   ├── Handlers
│   ├── Http
│   ├── Providers
│   └── Services
├── bootstrap
├── config
├── database
│   ├── migrations
│   └── seeds
├── public
│   ├── css
│   ├── fonts
|   └── grocery-crud
|   |   ├── css
|   |   ├── fonts
|   |   ├── images
|   |   └── js
├── resources
│   ├── assets
│   ├── lang
│   └── views
├── storage
│   ├── app
│   ├── framework
│   └── logs
├── tests
└── vendor

Step 6.
Now you need to create your configurations files in order to make grocery CRUD Enterprise to work. So basically there are 3 things that you will need to configured
1. Where the public folder is
2. The database configurations
3. The cache folder (this is optional but it is very recommended to do it as your CRUD can be 10X faster.)

You can find all the code below of the examples at:
vendor/grocerycrud/enterprise/example

There are 2 config files that you are required to configure. The first one is the database connection credentials. A simple database file like the below is required:

//database.php
<?php
return [
    'adapter' => [
        'driver' => 'Pdo_Mysql',
        'database' => 'db_name',
        'username' => 'db_username',
        'password' => 'db_password',
        'charset' => 'utf8'
    ]
];

As in grocery CRUD Enterprise we are using the power of Zend Framework the drivers are from Zend Framework DB version 2. For more you can see the documentation at Zend\Db\Adapter

The second configuration file is the one that you need to include for grocery CRUD. The configuration file will look like the below:

//config.php
<?php
return [
    // So far 34 languages including: Afrikaans, Arabic, Bengali, Bulgarian, Catalan, Chinese, Czech, Danish,
    // Dutch, English, French, German, Greek, Hindi, Hungarian, Indonesian, Italian, Japanese, Korean,
    // Lithuanian, Mongolian, Norwegian, Persian, Polish, Portuguese, Brazilian Portuguese, Romanian,
    // Russian, Slovak, Spanish, Thai, Turkish, Ukrainian, Vietnamese
    'default_language'	=> 'English',

    // This is the assets folder where all the JavaScript, CSS, images and font files are located
    'assets_folder' => '/assets/grocery-crud/',

    // There are only three choices: "uk-date" (dd/mm/yyyy), "us-date" (mm/dd/yyyy) or "sql-date" (yyyy-mm-dd)
    'date_format' => 'uk-date',

    // The default per page when a user firstly see a list page
    'default_per_page'	=> 10,

    // Having some options at the list paging. This is the default one that all the websites are using.
    // Make sure that the number of grocery_crud_default_per_page variable is included to this array.
    'paging_options' => ['10', '25', '50', '100'],

    // The environment is important so we can have specific configurations for specific environments
    'environment' => 'development',

    // This is basically in order to have a php cache. Be aware that in case you disble the php cache
    // things will get too slow
    'backend_cache' => false,

    'xss_clean' => false,

    // The character limiter at the datagrid columns, zero(0) value if you don't want any character
    // limitation to the column
    'column_character_limiter' => 50,

    // For more read http://framework.zend.com/manual/current/en/modules/zend.cache.storage.adapter.html
    // If you are not sure about how to use it, you can just change the ttl value (time to live) and
    // the file path of the cache
    'cache' => [
        'adapter' => [
            'name'    => 'filesystem',
            'options' => [
                'namespace' => 'gcrud',
                'ttl' => 3600 * 24 * 30 * 6,
                'cache_dir' => realpath(__DIR__ . '/Cache/')
            ],
        ],
        'plugins' => [
            'exception_handler' => ['throw_exceptions' => false],
        ],
    ],
];

At the config file there are 3 basic sections that we need to be aware of:

  1. The assets_folder:  The assets folder is the folder that can publicly be accessible by the end user. These folders includes: images, JavaScript files, fonts and stylesheets files.
  2. The environment: Make sure that the development environment is the one that you are using when you are developing the project. and production is the one that is used when you are publishing the website to production.
  3. The cache: Grocery CRUD is based on cache to do as less queries to the database as possible it is strongly advised to use cache to your project. The default cache is the files cache but of course you can change the cache configurations to add a faster method to cache. All the configurations for the cache can be found at:  Zend\Cache\Storage\Adapter

Step 7.

And now we are ready to make grocery CRUD Enterprise to put it to work! Let’s have an example of the very first use. A first example without any framework installation will look like this:

//example.php
<?php

include("vendor/autoload.php");

use GroceryCrud\Core\GroceryCrud;

$database = include('database.php');
$config = include('config.php');

$crud = new GroceryCrud($config, $database);

$crud->setTable('customers');
$crud->setSubject('Customer', 'Customers');
//$crud->columns(['customerName', 'contactLastName', 'contactFirstName']);

$output = $crud->render();

if ($output->isJSONResponse) {
    header('Content-Type: application/json; charset=utf-8');
    echo $output->output;
    exit;
}

$css_files = $output->css_files;
$js_files = $output->js_files;
$output = $output->output;

include('view.php');

And the view.php is a simple page (of course the implementation can be much better with a framework but this is just a quick example to see how easy you can install grocery CRUD Enterprise):

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <?php
    foreach($css_files as $file): ?>
        <link type="text/css" rel="stylesheet" href="<?php echo $file; ?>" />
    <?php endforeach; ?>

</head>
<body>
        <div style="padding: 20px 10px;">
            <?php echo $output; ?>
        </div>
        <?php foreach($js_files as $file): ?>
            <script src="<?php echo $file; ?>"></script>
        <?php endforeach; ?>
</body>
</html>

And congrats! You did install grocery CRUD Enterprise with composer. Now you can enjoy all the power of grocery CRUD Enterprise at your project and why not create something AWESOME today