Running commands attempts to load shell instead


#1

Hi,

I’m attempting to create a simple Command using an example from the CakePHP documentation found here.

I bake a command using bin/cake bake command Hello, thus creating a file called HelloCommand.php inside src/Command/.

The file contains the exact code the above link contains. However on running the command from console with the following command:

bin/cake hello

I get the following error:

Exception: Shell class for "Hello" could not be found. in [X:\xampp\htdocs\tools\vendor\cakephp\cakephp\src\Console\ShellDispatcher.php, line 327]

Why is it attempting to open a shell instead of the command. Am I missing something? If so I find it pretty unclear in the documentation.

Using CakePHP Version 3.6.4


#2

Did you add changes in PATH ?
https://book.cakephp.org/2.0/en/console-and-shells.html#the-cakephp-console
“Adding cake to your system path”


#3

You linked the 2.X documentation, but I’m on 3.X. On 3.X, I don’t believe you need to add the executable path to the PATH system variable. Instead you cd into your app folder, and run bin/cake.

Nevertheless, I added X:\xampp\htdocs\tools\bin to my System Variable called PATH, to no avail. Still the same error.

I can run shells fine without issues. I made a shell called ToolsShell. When I run bin/cake tools everything works fine. It’s only when I try to run a command, I have issues.


#4

Please, clarify :
You have some thing like :

class ToolsShell extends AppShell {
function hello(){}
}

And
bin/cake tools hello - Doesn’t works ?


#5

Hi, thanks.

Sorry for being unclear.

I have a file called HelloCommand.php inside src\Command folder.

Inside that file is the following code: https://gist.github.com/mentisy/79097cc825d6f4411263c07799b70755

File structure: http://tinypic.com/r/307xd2c/9

On the terminal, I’ve traversed using cd into my project folder. I run the command bin/cake Hello.

According to the documentation that should output Hello World. But I get the error shown in the top post.

Edit:

The reason I brought up the ToolsShell example, was to show that running Shells work perfectly according to documentation, but I understand Shell are deprecated.

I have this file inside src\Shell: https://gist.github.com/mentisy/6df9031b3027eb81f3c5dd2c83445a1e

When I run bin/cake Tools prolongedCheckouts, I get printed out all the rows I get using $this->Model->find().

So in essence: Shells work, Commands do not.