Php 使用lumen运行cron时:“插入”命名空间中没有定义任何命令。
我已经在laravel的lumen micro框架中为cron命令编写了如下代码Php 使用lumen运行cron时:“插入”命名空间中没有定义任何命令。,php,laravel,lumen,Php,Laravel,Lumen,我已经在laravel的lumen micro框架中为cron命令编写了如下代码 <?php namespace App\Console\Commands; use Illuminate\Console\Command; use App\Models\EmailDump; use DB; /** * dumpEmails Class * * This cron is to dump emails with cron use * * @author Hetal Gohel &
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use App\Models\EmailDump;
use DB;
/**
* dumpEmails Class
*
* This cron is to dump emails with cron use
*
* @author Hetal Gohel <hetal.gohel@brainvire.com>
*
*/
class dumpEmails extends Command {
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'insert:emails';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This cron is to dump emails with cron use';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
echo "1";die;
}
}
运行此命令时,会出现如下错误:
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Laravel\Lumen\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
\Laravelista\LumenVendorPublish\VendorPublishCommand::class,
'\App\Console\Commands\dumpEmails',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
// protected function schedule(Schedule $schedule)
// {
// return $schedule;
// }
}
php artisan insert:emails
[Symfony\Component\Console\Exception\CommandNotFoundException]←[39;49m
←[37;41m插入命名空间中未定义任何命令
请帮助我解决此问题。谢谢。请删除\uu构造并保留handle方法
此外,当您在内核的$commands下列出时,您需要指定类
那么你的
`\App\Console\Commands\dumpEmails`
变成
DumpEmails::class
一些额外提示:
类名大写;dumpemail->dumpemail
将{添加到新行;
这个
应该是
class DumpEmails extends Command
{
我还建议您查看一下。我留下了一个博客,我认为可能会帮助您开始使用它们,但请继续
最后,但并非最不重要的一点是,不要忘记命令父级已允许您使用其命令行潜力。因此,如果您希望输出和调试,您可以使用以下命令行进行输出和调试:
$this->info('Your message to inform');
$this->error('Your error message');
我已经做了以上的修改,仍然是同一个问题,我的lumen版本是5.2。*嗯,我可以要求你更新这些修改吗?所以我有一张关于如何在那里设置的地图吗?:据我目前所知,我相信删除_构造并在内核类中正确设置类就足够了e一个可能值得尝试的小更改。如果可以,请从内核类中删除指向命令类的默认路径。如果您注意到,我刚刚删除了\App\Console\Commands\dumpemail并保留为Commands\dumpemail。因为内核可能已经将其映射到默认文件夹,所以您应该编辑您的问题,而不是添加回答:P跟踪我们正在做的事情。给我几分钟时间,我检查一下further@hetalgohen我已经在我的本地计算机上安装并运行了它。这将使我的答案适应实际情况。基本上,现在您需要担心的是在内核类中声明它。确保它列为$commands参数下的dumpemail:::class。A另外,请确保您的文件是DumpEmails,而不是DumpEmails,并且文件中声明的类也遵循相同的规则。检查php artisan列表是否列出了所有现有命令后,让我知道1.它是否正常运行,2.是否现在列出了您的命令
$this->info('Your message to inform');
$this->error('Your error message');