1

Is there an alternate way of calling Zend's Framework Autoloader. I have this webpage where I load the Zend_Loader_Autoloader and then call the static method ::getInstance(). After having a lot of trouble wondering why my scripts do not work, I set up a test like this:

<?php 
$libreria='/home/u230474/public_classes/Zend/ZendFramework/library';
set_include_path(get_include_path().PATH_SEPARATOR.$libreria);
require_once('Zend/Loader/Autoloader.php');
$libload = Zend_Loader_Autoloader::getInstance();
if(!$libload) echo "Librer&iacute;a Zend Framework cargada"; else echo "Error al cargar la librer&iacute;a";

Which outputs "Error al cargar la librería".

I also have implemented the script installlationchecker.php to which I added the first two lines of that previous code, and, having installed Zend Framework on a sister folder to the public folder, the installation test passes.

But my question is, can I call the Autoloader like an object, say:

$libload = New Zend_Loader_Autoloader();

$libload->getInstance();

There seems to be nothing in Zend Framework's documentation about this alternate syntax.

I'm intending to do this because the library doesn't load on several scripts where I need it, and this only happens on the remote server, on my testing server it works fine. I put a test like this:

include ('header.php');
//codigo para probar equidad de nombre de archivo---------->
$filename = basename($_SERVER['SCRIPT_FILENAME']);
$request = basename($_SERVER['SCRIPT_NAME']);
if($filename != $request)
  die('Case of filename and request do not match!');
echo ('<div class="cuerpo"><div class="mensajes">');
if(isset($_POST['autoresArt'])&&isset($_POST['tituloArt'])&&isset($_POST['correoArt'])&&isset($_POST['descArt'])) {
require_once('libreria.php');

to see if there's a capitalization problem with my scripts (which were developed on windows) and the scripts in the Linux server, however there seems to be not a problem.

By the way, the only code that is outputted before requiring or including the library is 'header.php' which is just the html document to show the output, plus some javascript to control it.

P.D. I'm sorry I've checked it out and as Matt says it is outputting that the library is set. However I've been trying to get this code to work for days and since it fails in the remote server while not on my testing server I guessed the Zend Framework library wasn't being loaded. In fact, it wasn't, it was just today that I set it up right in a sister folder to the public folder and called the test script to be sure.

However, the code I set in the script doesn't run properly, it is something like:

if(isset($_POST['nombreUs'])) {
$nombreUsuario = reemplaza_blancos($_POST['nombreUs']);
$nombreUsuario = trim($nombreUsuario);
$nombreUsuario = mysql_real_escape_string($nombreUsuario);
$validaDos = new Zend_Validate_Regex('/^([[:alpha:]]|[ÁÉÍÓÚÑñáéíóúÄËÏÖÜäëïöü])[[:alpha:]]|[ÁÉÍÓÚÑñáéíóúÄËÏÖÜäëïöü]+\s?([[:alpha:]][ÁÉÍÓÚÑñáéíóúÄËÏÖÜäëïöü])?/');
if(!$validaDos->isValid($nombreUsuario)) {
$errors ['nombre'] = "El nombre no puede contener n&uacute;meros";  
}
}

and then I check if(empty($errors)) then call and run the PHPMailer class.

It makes me mindnumb to see that this script simply does not run properly

gerardo flores
  • 402
  • 1
  • 6
  • 28
  • The autoloader would normally be a Singleton. Instation would imply that multiple auto loaders would exist...how would you expect them to cooperate? How would you expect your syntax to behave differently than the provided static factory method? – Matt Whipple Oct 24 '12 at 03:02
  • @MattWhipple I'm not actually trying to run several instances of Autoloader class. I'm just trying to figure out why the library doesn't load on my scripts. I put this code `$libreria='/home/u230474/public_classes/Zend/ZendFramework/library'; set_include_path(get_include_path().PATH_SEPARATOR.$libreria); include_once('Zend/Loader/Autoloader.php'); $libload = Zend_Loader_Autoloader::getInstance(); if(!$libload) echo "Error al cargar la librería"; else echo "Librería cargada";` on the testing script installationchecker.php and it outputs 'libreria cargada" so it makes me wonder. – gerardo flores Oct 24 '12 at 03:12
  • It's outputting the else clause of the autoloader not being defined check...so the library _is_ defined. – Matt Whipple Oct 24 '12 at 03:16
  • @MattWhipple Yes, but it does only on the script installationchecker.php -why does it not output the same else clause on the rest of the scripts?- On the scripts I'm interested it outputs the if clause, see? – gerardo flores Oct 24 '12 at 03:23
  • I've given up on getting something clear about this. I've been trying to include or require the library on my original scripts (which were written on Dreamweaver CS5 on Windows 7) for over 2 days – gerardo flores Oct 24 '12 at 03:25
  • You have this hard coded path: `$libreria='/home/u230474/public_classes/Zend/ZendFramework/library';`, this should be generated relative to `__FILE__` in a way that will work portable – Matt Whipple Oct 24 '12 at 03:27
  • @MattWhipple sorry I realized it does output the else clause on all cases, just I mixed up what I was trying to check. Guess I must check why my scripts aren't working, which doesn't have to do with the library being loaded or not. Would it be too much bother to post some of the code that validates some user input, it's there that the script gets stuck, but only on the remote server. On my testing server it works fine. – gerardo flores Oct 24 '12 at 03:29
  • Yes I guess I should make it portable, but right now what bothers me is that the Zend_Validate_Alnum and Zend_Validate_Regex and Zend_Validate_Email is behaving oddly. Perhaps it is a problem of capitalization. Is there any test I can set up that doesn't check for the file name but for the nomenclature 'inside' my code? – gerardo flores Oct 24 '12 at 03:31
  • not sure, that would be another question and I'm done for the night. In general all of the file names should be handled portably though. – Matt Whipple Oct 24 '12 at 03:32
  • OK, thanks, it's a relief to see I was clearly making a mistake though, I was already declaring myself done with folder structure – gerardo flores Oct 24 '12 at 03:40

1 Answers1

0

You cannot have

$libload = New Zend_Loader_Autoloader();

simply because the constructor is declared as protected method.

protected function __construct()

So no, you cannot.

akond
  • 15,865
  • 4
  • 35
  • 55