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.

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



67.7k

i have had similour structures and i used registerNamespaces

first example here : https://docs.phalconphp.com/en/latest/api/Phalcon_Loader.html



1.7k

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.phalconphp.com/en/latest/api/Phalcon_Loader.html



67.7k
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



1.7k

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



67.7k
edited Sep '16

you also have to specify clasX dir

"dirA => models/DirA/



1.7k

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/



67.7k
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



1.7k

thank you !