On 4/8/06, Pablo L. de Miranda <pablolmiranda@xxxxxxxxx> wrote: > I has modified my code to this, notice wich all directories that I > refer is in the root of application: > > // File Controller.php in directory controller: > $file = '../util/ClassUtil.php'; > echo $file.'<br>'; > include $file; > $service = ClassUtil::loadClass('service.FormularioService'); > $service->helloWorld(); > > // File ClassUtil.php in diretory util: > class ClassUtil { > > function __construct() { > echo 'Construindo objecto'; > } > > static public function loadClass($class) { > $str = explode('.',$class) ; > $className = $str[count($str) - 1]; > > $obj = null; > > $exist = false; > $scriptName = $_SERVER['SCRIPT_NAME']; > $paths = explode('/', $scriptName); > $url = 'http://'.$_SERVER['HTTP_HOST']; > $appDir = $_SERVER['DOCUMENT_ROOT']; > > $class = str_replace(".", "/", $class); > $path = ""; > for ($i = 0; $i < count($paths) - 1; $i ++) { > $path .= '/'.$paths[$i]; > echo '<br>AppDir: '.$appDir.$path.'<br>'; > > $c = $appDir.$path.'/'.$class.'.php'; > > while (strstr($c, '//')) > $c = str_replace('//', '/', $c); > > echo 'Carregando classe: '.$c.'<br>'; > if (file_exists($c)) { > echo 'Carregando a URL: '.$url.$path.'/'.$class.'.php'; > include $url.$path.'/'.$class.'.php'; > $exist = true; > return new $className; > } > > } > if (!$exist) > echo 'ERRO: O ARQUIVO NAO EXISTE!...'; > } > } > > // File FormularioService.php in directory service: > class FormularioService { > > public function helloWorld() { > echo '<br>Hello World.<br>'; > } > } > $serv = new FormularioService; > $serv->helloWorld(); > > And my output in the browser is that: > ../util/ClassUtil.php > > argv: Array > argc: 1 > AppDir: /var/www// > Carregando classe: /var/www/service/FormularioService.php > > AppDir: /var/www///egressos > Carregando classe: /var/www/egressos/service/FormularioService.php > Carregando a URL: http://localhost//egressos/service/FormularioService.php > Hello World. > > Fatal error: Class 'FormularioService' not found in > /home/pldm/projetos/egressos/src/util/ClassUtil.php on line 44 What's in this file? /var/www/egressos/service/FormularioService.php (Always CC the list). -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php