Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Recently, I'm diving into symfony's class loader component. However, I need to solve an issue. I have the following folder structure;

-> project
    -> public
        -> index.php
    -> package
        -> Request.php

In index.php I'm using the following statements to load the class loader of Symfony;

define ('ROOT', dirname(dirname(__FILE__)));

$paths = array(
    'system' => ROOT . '/package'
);

$namespaces = array(
    'MyNamespace' => $paths['system']
);

require $paths['vendor'] .
    '/symfony/class-loader/Symfony/Component/ClassLoader/UniversalClassLoader.php';

use Symfony\Component\ClassLoader\UniversalClassLoader;

$autoload = new UniversalClassLoader();
$autoload->registerNamespaces($namespaces);
$autoload->register();

use MyNamespace\Request;

Request::create();

In Request.php, I have the following code;

namespace MyNamespace;

class Request
{
    static public function create()
    {

    }
}

However, in index.php file, It says that Request class can't be found

So, What am I doing wrong here ? Any ideas ?

share|improve this question
1  
Well. Before diving into this, is there any particular reason you can't use composer's autoload? Be glad to show you how. Even Symfony 2's framework uses composer instead of the UniversalClassLoader. – Cerad 20 hours ago
@Cerad thanks for the suggestion – aacanakin 20 hours ago
add comment (requires an account with 50 reputation)

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.