Created
October 15, 2012 06:51
-
-
Save toopay/3891122 to your computer and use it in GitHub Desktop.
SplClassLoader Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Let say we have these directory structure, that follow PSR-0 spec : | |
// | |
// system | |
// - framework | |
// - Http | |
// - Request.php | |
// - Response.php | |
// test.php | |
// SplClassLoader.php | |
// | |
// Then we could utilize it as : | |
require_once('SplClassLoader.php'); | |
$loader = new SplClassLoader('framework', 'system/framework'); | |
$loader->register(); | |
// Now we could call any classes within | |
// framework namespace without the need to include each files/classes | |
// as easy as : | |
$request = new Http\Request(); |
Could you elaborate on how the contents of Request.php and Response.php might look like?
$loader = new SplClassLoader('framework', 'system/framework');
use it like this
$loader = new SplClassLoader('framework', 'system');
What are the contents of Request.php or Response.php? This would be helpful.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to work this? I am is not understand.
My project have tree:
//system
//-framework
//--CForm.php
// index.php
// SplClassLoader.php
//the CForm.php have code
"; } public function endForm() { echo ""; } ``` } //And i using this code in index.php for loading my class: register(); //Folowing is example of using loader use CForm; $object1=new CForm(); $object1->startForm(); $object1->endForm(); //But i ave error Class 'CForm' not found in C:\OpenServer\domains\Formulator.loc\index.php