【问题标题】:Laravel Artisan command - "Class not found"Laravel Artisan 命令 - “找不到类”
【发布时间】:2018-12-19 12:11:54
【问题描述】:

好的,我这里有一些巫术魔法。 inb4 - 我已经让 composer dump 和 dump-autoload 100 000 次。

<?
namespace Cds\Goods\Classes;

use Cds\Goods\Classes\Logs;
use Cds\Goods\Classes\AttributeUniteFront;

class ShiptorSync extends Shiptor{

    public static function sync_products() {    
        Logs::add_to_log("shiptor_sync", date("d.m.Y"), "begin sync shiptor products");
        $name = AttributeUniteFront::getSlugProduct($item->cds_products_id);
    }
}

这是我在控制台命令中调用的函数 sync_products() 的类,就像那样

<?php
​
namespace App\Console\Commands;
​
use Cds\Goods\Classes\ShiptorSync;
use Illuminate\Console\Command;
​
/**
 * Class ShiptorSynchronizeProducts
 */
class ShiptorSynchronizeProducts extends Command
{
  /**
   * The name and signature of the console command.
   *
   * @var string
   */
  protected $signature = 'shiptor:products:synchronize';
​
  /**
   * The console command description.
   *
   * @var string
   */
  protected $description = 'Sync goods';
​
  /**
   * Execute the console command.
   */
  public function handle()
  {
    ShiptorSync::sync_products();
  }
}

每次我从控制台运行它时 - 找不到 Class 'Cds\Goods\Classes\AttributeUniteFront'

但是!成功找到类日志。什么鬼……

班级在他的位置

AttributeFront 得到了正确的命名空间

即使在 IDE 中,它也会使用灰色字体和错误来绘制,就像它在页面上未使用一样。会是什么????

不,这到底是什么?它告诉我找不到类,并错误地抛出了未找到类的完整列表!!!

【问题讨论】:

  • 第一行问题 - 做了 100 000 次
  • Cds\Goods\Classes\AttributeUniteFront 是这个类在 vendor 中的位置吗?
  • 十月CMS插件在文件夹/var/www/site.test/web/plugins/cds/goods/classes
  • 近类日志加载完美
  • 你能在注册这个命名空间的地方发布 composer.json 吗?

标签: php laravel laravel-artisan octobercms


【解决方案1】:

添加到命令控制器:

 public function __construct()
    {
        parent::__construct();
    }

在 Kernel.php 中:

protected $commands = [
        //
        '\App\Console\Commands\ShiptorSynchronizeProducts',
    ];

那么,为什么不在命令中处理()sync_products?此外,似乎没有定义 $item。

将此添加到命令文件中:

    use Cds\Goods\Classes\Logs;
    use Cds\Goods\Classes\AttributeUniteFront;

public function handle()
  {
    Logs::add_to_log("shiptor_sync", date("d.m.Y"), "begin sync shiptor products");
        $name = AttributeUniteFront::getSlugProduct($item->cds_products_id);
  }
}

【讨论】:

    【解决方案2】:

    天哪,我不知道为什么,但情况是打开短 PHP 标记,尽管启用了 short_open_tag。但是我改变了它,一切正常。

    【讨论】:

    • 您能否再解释一下您的解决方案?
    猜你喜欢
    • 2019-08-31
    • 2016-02-07
    • 1970-01-01
    • 2018-02-03
    • 2015-08-29
    • 2017-01-18
    • 2015-12-03
    • 2015-06-07
    • 2020-07-24
    相关资源
    最近更新 更多