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

Phalcon 4 dev tools cannot generate controller

when i tried to use the command : phalcon controller <name> it threw an error like this Phalcon DevTools (4.0.1)

Error: Builder can't locate the configuration file



8.4k

did you move /app/config/config.php?

What is your Phalcon version?

I did not move any files.

What is your Phalcon version? Phalcon 4.x



8.4k

check the phalcon version used in php CLI

php -r "var_dump(Phalcon\Version::get());"


8.4k

sorry for the late response

i'm actually using v3 at the moment and i had to match your environment and i was using osx at first and then i had another crack at it with another device which was windows and finally i got the same exception

it is a bug on windows environment

file: src/Builder/Path.php line: 63

change it to

if (preg_match('/config\.php$/i', $f->getPathName())) {

or

if (preg_match('/config\.php$/i', $f->getFilename())) {


100
edited Jun '20

sorry for the late response

i'm actually using v3 at the moment and i had to match your environment and i was using osx at first and then i had another crack at it with another device which was windows and finally i got the same exception

it is a bug on windows environment

file: src/Builder/Path.php line: 63

change it to

if (preg_match('/config\.php$/i', $f->getPathName())) {

or

if (preg_match('/config\.php$/i', $f->getFilename())) {

What a great and, of course, well written post. It`s so useful…

I am having the same issue and this did not help.

I am getting this message when trying to create a new controller:

Phalcon DevTools (4.0.3) Error: Builder can't locate the configuration file

Environment: OS: Windows NT DESKTOP-P2K7MSM 10.0 build 18363 (Windows 10) AMD64 PHP Version: 7.4.6 PHP SAPI: cli PHP Bin: C:\xampp\php\php.exe PHP Extension Dir: C:\php\ext PHP Bin Dir: C:\php Loaded PHP config: C:\xampp\php\php.ini Versions: Phalcon DevTools Version: 4.0.3 Phalcon Version: 4.0.6 AdminLTE Version: 2.3.6

sorry for the late response

i'm actually using v3 at the moment and i had to match your environment and i was using osx at first and then i had another crack at it with another device which was windows and finally i got the same exception

it is a bug on windows environment

file: src/Builder/Path.php line: 63

change it to

if (preg_match('/config\.php$/i', $f->getPathName())) {

or

if (preg_match('/config\.php$/i', $f->getFilename())) {


8.4k

the issue is as the exception says which is it can't locate config.php / config.ini

check the file mentioned before src/Builder/Path.php method: getConfig()

you can debug and use breakpoints or just dump $f->getPathName() inside the iterator

if you saw the config.php there your issue would be the regex doesnt match your config.php and therefore it can't locate it

i did open an issue regarding this matter #1426

Can you describe with some more detail what I should do to get the regex to match my config.php?



8.4k
edited Jun '20

did you install phalcon devtools globally ( composer global require phalcon/devtools ) ?

add this line after foreach ($iterator as $f) { line#62

var_dump($f->getPathName());

and check if the config.php does show up there your issue is in the regex on line#63

if not the issue would the path where you invoked phalcon devtools from

it should go like this:

C:\wamp\www\devtools_test
λ phalcon4 controller tester

Phalcon DevTools (4.0.3)

string(3) ".\."
string(4) ".\.."
string(11) ".\.htaccess"
string(15) ".\.htrouter.php"
string(12) ".\.phalcon\."
string(13) ".\.phalcon\.."
string(7) ".\app\."
string(8) ".\app\.."
string(14) ".\app\config\."
string(15) ".\app\config\.."
string(23) ".\app\config\config.php"
string(23) ".\app\config\loader.php"
string(23) ".\app\config\router.php"
string(25) ".\app\config\services.php"
string(19) ".\app\controllers\."
string(20) ".\app\controllers\.."
string(36) ".\app\controllers\ControllerBase.php"
string(37) ".\app\controllers\IndexController.php"
string(15) ".\app\library\."
string(16) ".\app\library\.."
string(18) ".\app\migrations\."
string(19) ".\app\migrations\.."
string(14) ".\app\models\."
string(15) ".\app\models\.."
string(13) ".\app\views\."
string(14) ".\app\views\.."
string(19) ".\app\views\index\."
string(20) ".\app\views\index\.."
string(29) ".\app\views\index\index.phtml"
string(23) ".\app\views\index.phtml"
string(21) ".\app\views\layouts\."
string(22) ".\app\views\layouts\.."
string(9) ".\cache\."
string(10) ".\cache\.."
string(12) ".\index.html"
string(10) ".\public\."
string(11) ".\public\.."
string(18) ".\public\.htaccess"
string(14) ".\public\css\."
string(15) ".\public\css\.."
string(16) ".\public\files\."
string(17) ".\public\files\.."
string(14) ".\public\img\."
string(15) ".\public\img\.."
string(18) ".\public\index.php"
string(13) ".\public\js\."
string(14) ".\public\js\.."
string(15) ".\public\temp\."
string(16) ".\public\temp\.."

  Error: Builder can't locate the configuration file

then went and removed var_dump($f->getPathName()); and changed line#63 to

if (preg_match('/config\.php$/i', $f->getFilename())) {

the result:

C:\wamp\www\devtools_test
λ phalcon4 controller tester

Phalcon DevTools (4.0.3)

  Success: Controller "tester" was successfully created.

  Info: C:\wamp\www\devtools_test\app\controllers\TesterController.php

Thank you for your answer. I re-installed devtools by using ( composer global require phalcon/devtools ). Where can I find the config.php now? Since I have installed devtools via the composer do I still need to do something with the batch file or the windows environment?



8.4k

i don't think you needed to install it globally but since you did you need to choose which one you prefer and remove the other one

what i mean by the other one is the one you had you issue with

i suggest you uninstall the global one and stick with your previous one

the config.php should be in phalcon_dir/app/config/

and you have to use phalcon devtools while you are in your phalcon project directory

I removed the old one before I installed with composer. Sorry i did not mean where I can find the config file but the src/Builder/Path.php file so I can change line #63. So to be clear, when I install the devtools with the composer where does the path.php file go?



8.4k

it should be in C:\Users\USER_NAME\AppData\Roaming\Composer\vendor\phalcon

OK it worked, thank you.

edited Sep '20
  1. open file in C:\Users\USER_NAME\AppData\Roaming\Composer\vendor\phalcon\devtools\src\Builder\Path.php

  2. edit function setRootPath : if($path) $this->rootPath = rtrim(str_replace('/', DIRECTORY_SEPARATOR, $path), '\/') . DIRECTORY_SEPARATOR; else $this->rootPath = realpath('.') . DIRECTORY_SEPARATOR;

  3. save it.

it's work for me.