I am a newer to cakephp .I config the cakephp shell as the cakephp
handbook says,when I run the HelloShell with the command cake
Hello ,I got the error information as follows:
Error: Shell class HelloShell could not be found.
1#G:\htdocs\cakedemo\lib\Cake\Console\ShellDispatcher.php(191):ShellDispatcher>_getShell('hello')
2#G:\htdocs\cakedemo\lib\Cake\Console\ShellDispatcher.php(69):ShellDispatcher->dispatch()
3#G:\htdocs\cakedemo\app\Console\cake.php(33):ShellDispatcher::run(Array) {main}
my cakephp version :
Welcome to CakePHP v2.2.0-beta Console
App : Console
Path: G:\htdocs\cakedemo\app\Console\
anyone who is helpful can give me a advice,plea.
there is your mistake.
you should always be in your APP path to execute the cake console.
...app/>../lib/Cake/Console/cake MyShell
or (using the APP Console folder):
...app/>Console/cake MyShell
and MyShell should then be in ...app/Console/Command/.
Thats all there is to it.
Error: Shell class HelloShell could not be found appear because: typo mistake or run command at wrong directory.
Solution:
1. Setup path for php.exe, cake.exe
2. For example, my Cake website root is:
C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5
Create new file in folder C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5\app\Console\Command\HelloShell.php with content:
class HelloShell extends AppShell {
public function main() {
$this->out('Hello world.');
}
}
3. Open cmd, type:
cd /d C:\tools\xampp1.8.3\htdocs\cakephp-2.5.5\app
cake hello
We use hello in command line to call HelloShell class, because "Convention over configuration".
Reference:
http://book.cakephp.org/2.0/en/console-and-shells.html#creating-a-shell
Make sure you give cake folder path in /var/www/html/Console/cake.php
ini_set('include_path', $root . PATH_SEPARATOR . 'Cake' . $ds . 'lib' . PATH_SEPARATOR . ini_get('include_path'));
Then go to root folder. In my case the location will be
/var/www/html/
then give the shell file name; hello is my shell name, that would be
/var/www/html/Console/cake hello
combining together
/var/www/html$ /var/www/html/Console/cake hello
Your shell will be executed.
Related
First of all let's start saying I am running the whole project in a Docker container and that means I don't have anything installed on the host.
Having that I am trying to debug a Symfony command which is kind of CLI script with the difference it's not being called as php script.php but as bin/console command.
What does the console file has inside it? See below:
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
set_time_limit(0);
/** #var Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
I have Xdebug installed and configured, I have phpStorm configured as well and that means using the browser (and the extension to enable/disable) I can debug whatever I want.
Typically this is how the command is executed from the console (bash):
<path_to_symfony>/bin/console quote:notify -d 120 -e <some_email>
Options are optional here and that means I can call the same as:
<path_to_symfony>/bin/console quote:notify
It will work both ways. I am using the docs from here to debug such command. Now this is how I am setting up the IDE to debug a Symfony command:
Go to Run/Debug Configuration
Click on Add button (little green + symbol)
Choose PHP Script
Name it as SF Command
At File box I wrote bin/console
At Arguments box I wrote quote:notify (which is my command)
But the IDE says first: Error: file not specified or invalid and then when I try to execute the command it says it's not a valid configuration. (also notice the little "X" which should means something is wrong)
What I am missing here? Can I get some help here? I am using the latest version of phpStorm.
Im trying to execute shell commands using ruby, but i cant change directory to PATH with blank spaces.
variable = %x[cd #{ENV["HOME"]}/Virtual\\ VMs/]
This is not working.
Thank you
To be absolutely safe:
path = File.join [ENV["HOME"], 'Virtual VMs']
variable = %x[cd '#{path}']
Please note, that cd has empty output, so to make sure it works one probably wants to do smth like:
path = File.join [ENV["HOME"], 'Virtual VMs']
variable = %x[cd '#{path}' && ls -la]
#⇒ "total 32\ndrwxr-xr-x ....."
What is ist supposed to do? You try to chdir into a directory, but then don't do anything in it. Your variable will be empty in any case. Aside from the fact that it is pointless to do, you can not reliably execute a cd by itself in this way, because it is not an executable file. You can see this if you just execute %x[cd]. You will get an Errno::ENOENT exception.
Maybe you should first describe in a broader context, what you want to achieve with your code. Where would you like to change the working directory? Within the Ruby process - in which case you have to use Dir.chdir - or in the child process - in which case you have to execute some command after the cd.
i'm a newbie in using codeigniter cli
i'm using xampp and my project located in
c:\xampp\htdocs\mycli\
my code is like this
public function myfunction($to = "WORLD"){
echo "HELLO {$to}!".PHP_EOL;
}
i trying to use this cmd line base on codeigniter tutorial on cli
c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
but it doesn't work it just showing index.php file. i also using htacess to remove the index.php in the url.
try the following code
cd /path/to/project
php index.php mycontroller myfunction test
Either you can execute php index.php controller action
or you can call it thorough the http protocol
wget http://example.com/example/test/bar/
curl http://example.com/example/test/bar/
Reference: http://mildcoder.com/handling-codeigniter-in-cli-and-cron-jobs/
step1: cmd
step2: check your cmd ->
"php -V"
if step2 got error: your php.exe is not in your sys's path{
step3:
c:\xampp\php\php c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
}
if step2 show like this: php 5.3.6 ...............{
step3 is:
php c:\xampp\htdocs\my_cli\index.php mycontroller myfunction "test"
}
I am trying to work out how to setup a Shell to run as a cron, I have created a TaskEmailerShell.php file at /app/Console/Command/TaskEmailerShell.php with the following code:
App::uses('CakeEmail', 'Network/Email');
class TaskEmailerShell extends AppShell {
public $uses = array('Task');
public function main()
{
// GENERATE AND SEND THE EMAIL
// ------------------------------------------------------------>
$email = new CakeEmail();
etc etc
I have followed the instructions here and when the cron runs I get this error:
/home/village/public_html/app/Console/cakeshell: line 14: cake: command not found
My cron command is:
/home/village/public_html/app/Console/cakeshell TaskEmailer -cli /usr/bin -console /Cake/Console -app /home/village/public_html/app >> /home/village/public_html/emailer_log.log
Any suggestions where I am going wrong?
The cakeshell script you're referring to there requires the cake console binary to be somewhere in PATH, or (at least from looking at the usage example), for you to have specified the full path to the Console with the -console argument. It looks like you've got a relative path there.
Personally I recommend just calling the cake console directly from your cron job. As other needs arise you may end up writing a script like cakeshell to wrap the console. You could try something like :
# m h dom mon dow command
*/5 * * * * /home/village/public_html/lib/Cake/Console/cake -app '/home/village/public_html/app/' TaskEmailer >> /home/village/public_html/emailer_log.log
Command not found usually means your PATH is the problem. Programs run from cron might not even have PATH set. Any script started by cron must set PATH near the beginning or it won't find any of the programs it is supposed to run.
The error occurs at line 14 in the file cakeshell: $cmd. cmd is set at line 4.
#!/bin/bash
TERM=dumb
export TERM
cmd="/opt/lampp/htdocs/MyApp/app/Console/cake"
while [ $# -ne 0 ]; do
if [ "$1" = "-cli" ] || [ "$1" = "-console" ]; then
PATH=$PATH:$2
shift
else
cmd="${cmd} $1"
fi
shift
done
$cmd
Originally line 4 is
cmd="cake"
Change it to absolute path like:
cmd="/opt/lampp/htdocs/MyApp/app/Console/cake"
where MyApp is the application directory. I have faced this problem even after PATH settings. Then mentioning the absolute path solved it.
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}
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
Run it at C:\wamp\www\gitgrow\app\. It should work.
cd C:\wamp\www\gitgrow\app
Console\cake email
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
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.