Symfony2文件找到的类不在其中 [英] Symfony2 File Found Class Was Not In It
问题描述
这是我的第一个问题,除了我不是英语为母语的人,所以对于新手的错误要提前表示歉意.
This is my first question, besides I'm not english-native speaker, so sorry in advance for newbie mistakes...
我从Symfony2开始,而且已经面临了几天的自动加载问题,我快要疯了.
I'm starting with Symfony2, and I've been facing an autoload problem for a couple of days, i'm getting crazy..
我只是想在我的AppBundle的DefaultController中使用一个PHP类.我已经读过做到这一点的方法是在config.yml中创建一个服务,并为匹配的类提供一个名称空间.
I'm just trying to use a PHP class inside my DefaultController of my AppBundle. I've read the way of doing this is by creating a service in my config.yml and giving a namespace to that class that matches.
Symfony告诉我它确实找到了文件,但是类不在其中,确切的错误是:
Symfony tells me that it does found the file but the class is not in it, the exact error is:
自动加载器的预期类"Priceget \ CollectorBundle \ Crawler \ Amazon"将在文件"/srv/www/lol.com/public_html/priceget/symfony/src/Priceget/CollectorBundle/Crawler/Amazon.php"中定义.找到了文件,但没有类,文件名或名称空间可能有错字.
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.
我的课就是这样:
<?php
namespace Priceget\CollectorBundle\Crawler\Amazon;
use Symfony\Component\HttpFoundation\Response;
class Amazon
{
public function getAll()
{
return new Response('l0l');
}
}
在我的DefaultController中,我这样称呼它:
In my DefaultController I'm calling it like that:
<?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:
And my config.yml piece:
services:
amazon.crawler:
class: Priceget\CollectorBundle\Crawler\Amazon
我已经尝试过:
- 空缓存
- 重新启动apache
- 将类扩展到Controller吗? :-Z
非常感谢您.
推荐答案
您的命名空间有误,请重命名:
Your namespace is wrong, rename it:
来自:namespace Priceget\CollectorBundle\Crawler\Amazon;
至:namespace Priceget\CollectorBundle\Crawler;
这篇关于Symfony2文件找到的类不在其中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!