2

I'm trying to setup symfony class loader component for one of my projects. When I try to create a new object from the Logger class I get

Fatal error: Class 'MyPrefix\Log\Logger' not found in /usr/htdocs/sf/index.php on line 12

Here is the structure of the project

/
 lib
    MyPrefix
      Log
        Logger.php
 vendor/
 index.php

Here is the content of index.php file

<?php 
require_once 'vendor/autoload.php'; 

use Symfony\Component\ClassLoader\ClassLoader;

$loader = new ClassLoader();
$loader->addPrefix('MyPrefix', __DIR__ .'/lib/MyPrefix/');
$loader->register();


use MyPrefix\Log\Logger;
$logger = new Logger();

What I'm doing wrong?

2
  • Shouldn't it be use MyPrefix\Logger\Logger? Commented Dec 12, 2013 at 10:45
  • @Lauri Elias the directory name was wrong. I've updated the question. Commented Dec 12, 2013 at 10:47

1 Answer 1

1

When you add new prefix for namespace, you should give parent directory.

So for MyPrefix it is __DIR__ . '/lib/'

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.