We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,151 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Help with Namespaces & Autoload

I want to convert my MVC framework to conform to the PSR-0 standards, but I am having a devil of a time trying to wrap my head around namespaces and how it works. I am using the suggested SplClassLoader class. Below is my file structure, and what I am trying to accomplish.

index.php
application
system
---------Classes
----------------Autoloader.php
----------------Extension.php
---------config
----------------helper.php

index.php:

require( SYS_PATH . 'config/constants.php');
require( SYS_PATH . 'application.php');
require( SYS_PATH . 'Classes/Autoloader.php');

use Classes\Autoloader;
$classLoader = new Autoloader('Classes', BASE_PATH . 'system');
$classLoader->register();

$app = new Bootstrap();

Extension.php:

<?php if ( ! defined('BASE_PATH')) exit('No direct script access allowed');

namespace Classes;

class Extension {

        public __construct() {
             echo 'This Extension class is working';
        }

}

helper.php

<?php if ( ! defined('BASE_PATH')) exit('No direct script access allowed');

use Classes\Extension as Ext;
$apphelp = new Ext();
$apphelp->helper(array('gettext'));

The helper.php file is automatically loaded through a registry.php file, so there are no issues there. Now that all that is place, I am getting the following error:
Fatal error: Class 'Classes\Extension' not found in /Applications/MAMP/htdocs/framework/system/config/helper.php on line 21

I can't figure out what I am doing wrong. Like I said, I am still trying to understand namespaces, but I thought I was making progress, but I've been struggling with this for two days now. I know that "namespace" is supposed to come first in the code, and I did make that change even though it doesn't look so above, but I still receive errors. Any help is greatly appreciated.

2
Contributors
1
Reply
6 Hours
Discussion Span
9 Months Ago
Last Updated
3
Views
Question
Answered
joshmac
Junior Poster in Training
84 posts since Apr 2008
Reputation Points: 16
Solved Threads: 5
Skill Endorsements: 0

I came across this SO thread, not sure if yours is the same issue though.

pritaeas
Posting Prodigy
Moderator
9,293 posts since Jul 2006
Reputation Points: 1,178
Solved Threads: 1,462
Skill Endorsements: 86
Question Answered as of 9 Months Ago by pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0714 seconds using 2.69MB