Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running CakePHP Shell Script

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}
like image 568
Harsha M V Avatar asked Jul 19 '12 07:07

Harsha M V


4 Answers

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
like image 117
Krishna Avatar answered Sep 23 '22 05:09

Krishna


Run it at C:\wamp\www\gitgrow\app\. It should work.

cd C:\wamp\www\gitgrow\app
Console\cake email
like image 22
uzyn Avatar answered Sep 23 '22 05:09

uzyn


If your shell class is in the right place, then it might be a problem that cake does not know where your app root is. You can specify this using the -app argument.

cake -app ../app email
like image 28
ifunk Avatar answered Sep 22 '22 05:09

ifunk


See the following link about how to run Cake shells in cron:

http://book.cakephp.org/2.0/en/console-and-shells/cron-jobs.html

Your cron command basically calls cd into the app directory and the cake command to run the shell together.

like image 24
Yoseph Avatar answered Sep 23 '22 05:09

Yoseph