duanmie9741 2012-08-18 14:17
浏览 27
已采纳

正在加载第三方库:未找到

I am trying to include a third party library into my Symfony 2 project as explained here. However, I keep getting the error message Fatal error: Class 'Sprain_Images' not found in /src/MyProject/MyBundle/Controller/BackendController.php on line 267.

Here is what I did:

I put a third party class into the src folder (not directly in vendors because this class is not available to be loaded by deps).

#Directory structure
-src
  -MyProject
  -vendor
     -sprain
       -lib
         -Images
           -src
           Images.php

Then I created the class to be used:

 # /src/vendor/sprain/lib/Images/Images.php
 require_once __DIR__.'/src/class.Images.php';
 class Sprain_Images extends Images {
 }

I also registered the prefix in autoload.php:

# /app/autoload.php
$loader->registerPrefixes(array(
  'Twig_Extensions_' => __DIR__.'/../vendor/twig-extensions/lib',
  'Twig_'            => __DIR__.'/../vendor/twig/lib',
  'Sprain_'          => __DIR__.'/../src/vendor/sprain/lib',
));

And eventually I called the class in my controller:

# /src/MyProject/MyBundle/Controller/BackendController.php
$image = new \Sprain_Images();

However the class is not being found. Where did I make the mistake?

  • 写回答

2条回答 默认 最新

  • dsmlf1207915 2012-08-18 14:30
    关注

    The class Sprain_Images should be in src/vendor/sprain/lib/Sprain/Images.php.

    You can read more about the PSR-0 standard : https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md#underscores-in-namespaces-and-class-names

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!