gpt4 book ai didi

php - Symfony2 文件发现类不在其中

转载 作者:可可西里 更新时间:2023-11-01 13:35:45 24 4
gpt4 key购买 nike

这是我的第一个问题,此外我的母语不是英语,对于新手的错误提前道歉...

我从 Symfony2 开始,几天来我一直面临自动加载问题,我快疯了..

我只是想在我的 AppBundle 的 DefaultController 中使用一个 PHP 类。我读过这样做的方法是在我的 config.yml 中创建一个服务并为匹配的类提供一个命名空间。

Symfony 告诉我它确实找到了文件但是类不在里面,确切的错误是:

The autoloader expected class "Priceget\CollectorBundle\Crawler\Amazon" to be defined in file "/srv/www/lol.com/public_html/priceget/symfony/src/Priceget/CollectorBundle/Crawler/Amazon.php". The file was found but the class was not in it, the class name or namespace probably has a typo.

我的类(class)就是这样:

<?php

namespace Priceget\CollectorBundle\Crawler\Amazon;

use Symfony\Component\HttpFoundation\Response;

class Amazon
{

public function getAll()
{
return new Response('l0l');
}
}

在我的 DefaultController 中,我这样调用它:

<?php

namespace Priceget\CollectorBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Guzzle\Http\Client;
use Symfony\Component\DomCrawler\Crawler;
use Priceget\CollectorBundle\Crawler\Amazon;

class DefaultController extends Controller
{

public function indexAction()
{
$amazon = $this->get('amazon.crawler');
}
}

还有我的 config.yml 部分:

services:
amazon.crawler:
class: Priceget\CollectorBundle\Crawler\Amazon

我已经尝试过:

  • 清空缓存
  • 重启apache
  • 将类扩展到 Controller ? :-Z

非常感谢您。

最佳答案

你的命名空间有误,重命名:

来自:命名空间 Priceget\CollectorBundle\Crawler\Amazon;

到:命名空间 Priceget\CollectorBundle\Crawler;

关于php - Symfony2 文件发现类不在其中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19080796/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com