Running CakePHP Shell Script

Harsha M V picture Harsha M V · Jul 19, 2012 · Viewed 15.5k times · Source

I have created a shell script as follows

<?php

class EmailShell extends AppShell
{
    public function main()
    {
        $this->out('Hello world.');
    }
}

When i navigate to the Console folder in command line and type cake email i get the following error.

Error: Shell class EmailShell could not be found.
#0 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(167): ShellDispatche
r->_getShell('email')
#1 C:\wamp\www\gitgrow\lib\Cake\Console\ShellDispatcher.php(69): ShellDispatcher
->dispatch()
#2 C:\wamp\www\gitgrow\app\Console\cake.php(33): ShellDispatcher::run(Array)
#3 {main}

Answer

Krishna picture Krishna · Jul 19, 2012

create a shell for use in the Console. For this example, we’ll create a simple Hello world shell. In you applications Console/Command directory create EmailShell.php. Put the following code inside it:

class EmailShell extends AppShell {
    public function main() {
        $this->out('Hello world.');
    }
}

Then run this command :

Console/cake email

or

cake email