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

subFolders in Models directory

Hello,

Yesterday i upgrade Phalcon to 3.0. Since, i have a problem, all class in sub-directory of « models » directory not work :

/models/
|- classA.php
|- classB.php
|- dirA/
    |- classC.php (classname = dirA_ClassC)

ClassC.php not working : When i call a function in this class i have this error:

PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0
PHP Fatal error:  Class 'dirA_ClassC' not found in /usr/share/nginx/html/test.php on line 6

But for ClassA & ClassB it's work.

Even if i register dirA :

$loader->registerDirs(
    array(
        __DIR__ . '/../models/'
    )
)->register();

or

$loader->registerDirs(
    array(
        __DIR__ . '/../models/dirA'
        __DIR__ . '/../models/'
    )
)->register();

It's not working...

Thank you



85.5k

i have had similour structures and i used registerNamespaces

first example here : https://docs.phalcon.io/en/latest/api/Phalcon_Loader.html



5.9k

Now, with Phalcon 3.0 it's mandatory to register nameSpaces?

i have had similour structures and i used registerNamespaces

first example here : https://docs.phalcon.io/en/latest/api/Phalcon_Loader.html



85.5k
edited Sep '16

i am actually not sure because i only use registerNamespaces , but i am pretty sure you should also use it always :D

u can create a simple test case with just few lines in it and if its not working you can report it as an issue here



5.9k

Ok i update my application to use namespace but i have a problem again :

|- models/
|- ClassA.php
|- ClassB.php
|- DirA/
    |- ClassX.php
    |- ClassY.php

I register namespace to have :

DirA => '/models/DirA/'

in ClassX.php i have :

class ClassX { static public function test() { return "x"; } }

in ClassY.php i have :

class ClassY extends DirA\ClassX { static public function testy(){ return 'y'; } }

But don't work.... Why ?

PHP Fatal error:  Class 'DirA\ClassX' not found

i am actually not sure because i only use registerNamespaces , but i am pretty sure you should also use it always :D

u can create a simple test case with just few lines in it and if its not working you can report it as an issue here



85.5k
edited Sep '16

you also have to specify clasX dir

"dirA => models/DirA/



5.9k

already specified :

$loader = new Loader();

$loader->registerDirs(
    array(
        __DIR__ . '/../models/',
        __DIR__ . '/../models/DirA/',
    )
);

$loader->registerNamespaces(
    array(
        'DirA' => __DIR__ . '/../models/DirA/',
    )
);

$loader->register();

you also have to specify clasX dir

"dirA => models/DirA/



85.5k
Accepted
answer

a.php

namaspeace spaceA;

class a(){}

dir/b.php

namespace spaceA/dir;

class b(){}

$loader->registerNamespaces(
    array(
        'spaceA' => '/var/www/html/myApp/SpaceA',
        'spaceA\dir' => '/var/www/html/myApp/SpaceA/dir',
    )
);

shoud be like that



5.9k

thank you !