ThaDafinser / ZfcDatagrid

New package available here (see website)
https://github.com/zfc-datagrid/zfc-datagrid/
MIT License
87 stars 57 forks source link

unable to fetch or create an instance for ZfcDatagrid\Datagrid #149

Closed amitshahin closed 9 years ago

amitshahin commented 9 years ago

Hello,

I have setup zfcdatagrid in my project using composer. ZfcDatagrid folder is copied at \vendor\thadafinser\zfc-datagrid\src\ZfcDatagrid location.

I have added below code in the module.config.php file

return array(
    'controllers' => array(
        'invokables' => array(
            'Users\Controller\Users' => 'Users\Controller\UsersController',
        ),
    ),
    'router' => array(
        'routes' => array(
            'stickynotes' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/users[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Users\Controller\Users',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),
    'view_manager' => array(
        'template_path_stack' => array(
            'users' => __DIR__ . '/../view',
        ),
    ),
'ZfcDatagrid' => array(

    'settings' => array(

        'default' => array(
            'renderer' => array(
                'http' => 'bootstrapTable',
                'console' => 'zendTable'
            )
        ),

        'export' => array(
            'enabled' => true,

            // currently only A formats are supported...
            'papersize' => 'A4',

            // landscape / portrait (we preferr landscape, because datagrids are often wide)
            'orientation' => 'landscape',

            'formats' => array(
                // renderer -> display Name (can also be HTML)
                'PHPExcel' => 'Excel',
                'tcpdf' => 'PDF'
            ),

            // The output+save directory
            'path' => 'public/download',

            'mode' => 'direct'
        )
    ),

    'cache' => array(

        'adapter' => array(
            'name' => 'Filesystem',
            'options' => array(
                'ttl' => 720000, // cache with 200 hours,
                'cache_dir' => 'data/ZfcDatagrid'
            )
        ),
        'plugins' => array(
            'exception_handler' => array(
                'throw_exceptions' => false
            ),

            'Serializer'
        )
    ),

    'renderer' => array(
        'jqGrid' => array(
            'templates' => array(
                'layout' => 'zfc-datagrid/renderer/jqGrid/layout'
            )
        )
    )
),

);

In controller file I have mentioned below code in action function.

    $data = new ViewModel(array(
                'users' => $this->getUsersTable()->fetchAll(),
            ));

     /* @var $grid \ZfcDatagrid\Datagrid */
    $grid = $this->getServiceLocator()->get('ZfcDatagrid\Datagrid');
    $grid->setTitle('Minimal grid');
    $grid->setDataSource($data);

    $col = new Column\Select('user_name');
    $col->setLabel('User Name');
    $grid->addColumn($col);

    $grid->render();

    return $grid->getResponse();

Also added below line at the top of the controller file. use ZfcDatagrid\Column;

but when I am trying to call url in browser, i am getting below error.

"Message:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for ZfcDatagrid\Datagrid"

Can you please let me know whether I have implemented something wrong or missed any piece of code?

Regards

ThaDafinser commented 9 years ago

@amitshahin see installation: https://github.com/ThaDafinser/ZfcDatagrid/blob/master/docs/02.%20Quick%20Start.md#installation

Do you added the module to be loaded? application.config.php

amitshahin commented 9 years ago
<?php
return array(
    'modules' => array(
        'Application',
        'StickyNotes',
        'Users',
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);

Above is the code added in the application.config.php file. I have already checked the installation link but it doesn't help me to resolve this issue.

I am trying to implement zfcdatagrid in user module.

ThaDafinser commented 9 years ago

You dont load the module (also stands in the installation). This is equal for each module you want to use (your modules or vendor modules)

<?php
return array(
    'modules' => array(
        'ZfcDatagrid', //<----------- ADD THIS
        'Application',
        'StickyNotes',
        'Users',
    ),
    'module_listener_options' => array(
        'config_glob_paths'    => array(
            'config/autoload/{,*.}{global,local}.php',
        ),
        'module_paths' => array(
            './module',
            './vendor',
        ),
    ),
);