Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DevTools cannot create controllers #1506

Closed
goldmont opened this issue Jun 27, 2021 · 4 comments
Closed

DevTools cannot create controllers #1506

goldmont opened this issue Jun 27, 2021 · 4 comments
Assignees

Comments

@goldmont
Copy link

goldmont commented Jun 27, 2021

Thank you for your efforts.

Actual Behavior

Command:
phalcon create-controller --name test

Phalcon DevTools cannot create a controller. Crash log:

PHP Fatal error: Uncaught Error: Call to a member function path() on int in /opt/phalcon-devtools/scripts/Phalcon/Builder/Controller.php:74
Stack trace:
#0 /opt/phalcon-devtools/scripts/Phalcon/Commands/Builtin/Controller.php(74): Phalcon\Builder\Controller->build()
#1 /opt/phalcon-devtools/scripts/Phalcon/Script.php(117): Phalcon\Commands\Builtin\Controller->run(Array)
#2 /opt/phalcon-devtools/scripts/Phalcon/Script.php(151): Phalcon\Script->dispatch(Object(Phalcon\Commands\Builtin\Controller))
#3 /opt/phalcon-devtools/phalcon(76): Phalcon\Script->run()
#4 {main}
thrown in /opt/phalcon-devtools/scripts/Phalcon/Builder/Controller.php on line 74

My config.php

<?php

defined('BASE_PATH') || define('BASE_PATH', getenv('BASE_PATH') ?: realpath(dirname(__FILE__) . '/../..'));
defined('APP_PATH') || define('APP_PATH', BASE_PATH . '/app');

return new \Phalcon\Config([
    'database' => [
        'adapter'     => 'Mysql',
        'host'        => 'mysql',
        'username'    => 'root',
        'password'    => '',
        'dbname'      => 'phalcon',
        'charset'     => 'utf8',
    ],
    'application' => [
        'appDir'         => APP_PATH . '/',
        'controllersDir' => APP_PATH . '/controllers/',
        'modelsDir'      => APP_PATH . '/models/',
        'migrationsDir'  => APP_PATH . '/migrations/',
        'viewsDir'       => APP_PATH . '/views/',
        'pluginsDir'     => APP_PATH . '/plugins/',
        'libraryDir'     => APP_PATH . '/library/',
        'cacheDir'       => BASE_PATH . '/cache/',
        'baseUri'        => '/',
    ]
]);

Details

  • System info and versions (if possible): Phalcon DevTools Version: 3.4.11
  • Phalcon Framework version: 3.4.5
  • PHP Version: 7.3.28-2+ubuntu20.04.1+deb.sury.org+1
  • Operating System: Ubuntu 20.04
  • Server: Apache
  • Other related info (Database, table schema): MySQL
@Ultimater Ultimater self-assigned this Jul 5, 2021
@Ultimater
Copy link
Member

I was able to recreate this on DevTools Version 3.4.11 as well as DevTools Version 3.4.12 (the latest which can be used with Phalcon 3)

The steps for me to recreate were:

phalcon project new
cd new
phalcon create-controller --name test

I also tried this on DevTools Version v4.1.0 and was not able to recreate it on v4.1.0.

The cause of the issue is related to devtools not being able to find the config.php in the usual place, due to the rootPath path somehow getting set to / in phalcon-devtools/scripts/Phalcon/Builder/Path.php, and it falls back to recursive directory searching and a regular expression:
preg_match('/config\.php$/i', $f->getPathName())
and this unexpectedly matches public/webtools.config.phpbefore app/config/config.php, finding the wrong config file.

I was able to also get it working again with a quick and dirty fix by adding an if statement so it doesn't match the wrong config file:

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

I'm currently working on a more proper fix for this.

Ultimater added a commit to Ultimater/phalcon-devtools that referenced this issue Jul 5, 2021
Ultimater added a commit that referenced this issue Jul 5, 2021
@Ultimater
Copy link
Member

This is fixed in v3.4.13

@goldmont
Copy link
Author

goldmont commented Jul 7, 2021

Thank you.

@rajeshpavasi
Copy link

I'm getting error while run "phalcon create-project test"

Phalcon DevTools (4.2.0)

PHP Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48

Fatal error: Uncaught Error: Class "Phalcon\Config" not found in C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php:48
Stack trace:
#0 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Commands\Builtin\Project.php(74): Phalcon\DevTools\Builder\Component\AbstractComponent->__construct(Array)
#1 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Script.php(109): Phalcon\DevTools\Commands\Builtin\Project->run(Array)
#2 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Script.php(148): Phalcon\DevTools\Script->dispatch(Object(Phalcon\DevTools\Commands\Builtin\Project))
#3 C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\phalcon(65): Phalcon\DevTools\Script->run()
#4 {main}
thrown in C:\xampp\htdocs\phalcon_dev\vendor\phalcon\devtools\src\Builder\Component\AbstractComponent.php on line 48

but i installed below :

Phalcon DevTools (4.2.0)

Environment:
OS: Windows NT DESKTOP-A40AND7 10.0 build 19044 (Windows 10) AMD64
PHP Version: 8.0.25
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.2.0
Phalcon Version: 5.0.0
AdminLTE Version: 3.0.1

so please kindly help me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants