We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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



85.5k
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 ...


8.4k

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

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 ...