Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Using Plugin with namespace

hi I am using Phalcon Datatables Plugin based on that source files are in my plugins folder and I"ve already registered that php "pluginsDir" => APP_PATH . "/app/plugins/",

I"ve got my own namespace

php $dispatcher->setDefaultNamespace("MyNS\Controllers");

DataTables has its own namespace as well.

when I try to use it, it couldn"t find classname DataTable

    My Controller

        namespace MyNS\Controllers;
        ...
        use DataTables\DataTable;
        ...
        use \DataTables\DataTable;

        $dataTables = new DataTable();
        ...
        $dataTables = new \DataTable();     
        ...
        $dataTables = new \DataTables\DataTable();      
        ...

Class "DataTables\DataTable" not found in none of them worked..!

edited Oct '15

Hi,

i suggest you to use Composer to install dependencies.

https://getcomposer.org/

Also datatables can be installed via composer. By this way u dont have to warry about classnames and loaders.

The only line that you will need in your Phalcon project will be this one, and you can insert this in the app/config/loader.php or in the public/index.php file

require_once __DIR__ . '/../../vendor/autoload.php';

To use composer create a composer.json file in your root project, edit the file and insert the required dependency:

Installation via Composer

Install a composer Create composer.json file inside your project directory Paste into it

{
    "require": {
        "m1ome/phalcon-datatables": "1.*"
    }
}

Run composer update



60.9k
Accepted
answer

you configured your loader right ?

define('COMMON_CLASSES_DIR', '/var/www/html/app/CommonClasses/');

$loader = new Loader();

        $loader->registerNamespaces([
            "CommonClasses\Enums"            => COMMON_CLASSES_DIR . "Enums" . DS
        ]);

and after that your classname should be the name of the file.

so if you want Enums\Tickets you sohuld have a file :

/var/www/html/app/CommonClasses/Enums/Tickets.php

and this file sohuld have

class Tickets bla bla bla ...


3.5k

thanks. I've registered namespaces although i'd registered class path but that didn't work

you configured your loader right ?

```php

define('COMMONCLASSESDIR', '/var/www/html/app/CommonClasses/');

$loader = new Loader();

   $loader->registerNamespaces([
     "CommonClasses\Enums"            => COMMON_CLASSES_DIR . "Enums" . DS
 ]);

```

and after that your classname should be the name of the file.

so if you want Enums\Tickets you sohuld have a file :

``` /var/www/html/app/CommonClasses/Enums/Tickets.php ```

and this file sohuld have

```php

class Tickets bla bla bla ...

```