这是我的第一个问题,除了我不是英语母语的人,提前为新手的错误很抱歉...Symfony2的文件是不是在这
我开始与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.
而我的班就是这样的:
<?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
- 扩展类控制器? :-Z
非常感谢你提前。
通过这样做,它返回文件未找到,自动加载错误。顺便说一句,我的文件夹结构是:src/Priceget/CollectorBundle/Crawler/Amazon。任何建议? – manelgarcia
如果你有“亚马逊”文件夹和“Amazon.php”文件,那么你需要将服务类定义更改为:'Priceget \ CollectorBundle \ Crawler \ Amazon \ Amazon' –
我不想,我错过了.php文件:P文件结构是:src/Priceget/CollectorBundle/Crawler/Amazon。PHP,如果我摆脱'亚马逊'系统引发:FatalErrorException:错误:类'Priceget \ CollectorBundle \ Crawler'找不到/srv/www/domain.es/public_html/priceget/symfony/app/cache/dev/ appDevDebugProjectContainer.php – manelgarcia