Skip to content

Installation and Configuration

wuethrich44 edited this page Oct 14, 2014 · 12 revisions

Installation

1. Basic (Download module)

1.1. By cloning

Clone this project into your ./vendor/ directory.

1.2. With composer

Add this project in your composer.json:

{
    ...
    "require": {
        "zendframework/zendframework": "2.3.*",
        "dudapiotr/zftable": "dev-master"
    }
}

Optional if You want to use Doctrine or AssetManager functionality add below code

{
    ...
    "require": {
        "zendframework/zendframework": "2.3.*",
        "dudapiotr/zftable": "dev-master",
        "doctrine/doctrine-orm-module": "0.*",
        "rwoverdijk/assetmanager" : "dev-master"
    }
}

2. Post installation

2.1 Enabling module

Enabling it in your application.config.php file.

<?php
    return array(
        'modules' => array(
            // ...
            'ZfTable',
        ),
        // ...
    );
// ...

2.2 Copying required files

  • Look at ..vendor\dudapiotr\zftable\src\ZfTable\Public folder. There are css, js and img folder. Most of them are optional, but if you install this module first time please copy all files to Your Public folder (zfproject/public/)

  • Add all required scripts (css nad js ) to Your layout - My configuration looks like that:

<!-- CSS SCRIPTS -->
<?php
echo $this->headLink(array(
                        'rel' => 'shortcut icon', 
                        'type' => 'image/vnd.microsoft.icon', 
                        'href' => $this->basePath() . '/img/favicon.ico'
                    ))

                    ->prependStylesheet($this->basePath() . '/css/bootstrap-3.0.0/bootstrap.min.css')
                    ->prependStylesheet($this->basePath() . '/css/style.css')
                    ->prependStylesheet($this->basePath() . '/css/zf-table/zf-table.css')        

                    //->prependStylesheet($this->basePath() . '/css/bootstrap-2.2.2/DT_bootstrap.css')
                    //->prependStylesheet($this->basePath() . '/css/bootstrap-2.2.2/bootstrap-responsive.min.css')
                    //->prependStylesheet($this->basePath() . '/css/bootstrap-2.2.2/bootstrap.min.css')             
?>

<!-- JS SCRIPTS -->
<?php 
echo $this->headScript()->appendFile($this->basePath() . '/js/jquery.min.js') 
                        ->appendFile($this->basePath() . '/js/jquery.dataTables.min.js')    
                        ->appendFile($this->basePath() . '/js/zf-table.js')  
                        ->appendFile($this->basePath() . '/js/DT_bootstrap_3.js')  
                        //->appendFile($this->basePath() . '/js/DT_bootstrap_2.js')  
                
?>

"//" for enabling and disabling funcionality like switching between Bootstrap 2 and 3

2.3. Your-Project/config/autoload/global.php

ZfTable needed set up database configuration, if You want to get data from it. (My configuration of global.php)

<?php
return array(
    'db' => array(
        'driver'         => 'Pdo',
        'username'       => 'root',
        'dsn'            => 'mysql:dbname=tabeleczka;host=localhost',
        'driver_options' => array(
            PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
        ),
    ),
    'service_manager' => array(
        'factories' => array(
            'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
        ),
    ),
    'doctrine' => array(
        'connection' => array(
            'orm_default' => array(
                'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
                'params' => array(
                    'host'     => 'localhost',
                    'port'     => '3306',
                    'user'     => 'root',
                    'password' => '',
                    'dbname'   => 'tabeleczka',
                )
            )
        )
    ),
);

2.4. If You want to see how it works - example tables, in ZfTable/data/customer.sql there are sample data.

2.5 Run sample table (http://your-project/table/base). You should see full working table.

Controller is located in ZfTable/src/ZfTable/Controller/TableController

/**
 * ********* Base *******************
 * ***********************************
 */
public function baseAction()
{
}
public function ajaxBaseAction()
{
    $table = new TableExample\Base();
    $table->setAdapter($this->getDbAdapter())
            ->setSource($this->getSource())
            ->setParamAdapter($this->getRequest()->getPost())
    ;
    return $this->htmlResponse($table->render());
}

View is located in ZfTable/view/zf-table/table/base.phtml

<div id="tableContainer"></div>
*
*
*
<script>
    $("#tableContainer").zfTable('/table/ajax-base');
</script>

Table class is located in ZfTable/src/ZfTable/Example/TableExample/Base.php

2.6. Any problems ?

  1. By default is called url like below, so you have to set Your project correctly. Look at that:

http://framework.zend.com/manual/2.3/en/user-guide/skeleton-application.html#using-the-apache-web-server

<script>
    $("#tableContainer").zfTable('/table/ajax-base');
</script>

3. Configuration

Basic configuration : http://dudapiotr.eu/table/changes

ToDo