gerardo flores
gerardo flores

Reputation: 422

Modifying .htaccess file to set include path to ZendFramework

I'm trying to include ZendFramework on a web site with no luck. Lately I gave a try at modifying the .htaccess file like this:

php_value include_path ":/home/u230474/Zend"

I also tried

php_value include_path ".:/home/u230474/Zend"

But on each case what happened was that I no longer could view any of the pages in the web site.

I did these modifications since I'm trying to make the system understand the following code:

<?php 
$libreria='/Zend/ZendFramework/library';
set_include_path(get_include_path().PATH_SEPARATOR.$libreria);
require_once('Zend/Loader/Autoloader.php');
Zend_Loader_Autoloader::getInstance(); 

I've been trying things many days long now, and although I've talked to my provided we seem to have problems understanding the requirements.

I did a test to check the installation of ZendFramework with a script called InstallationChecker.php which is supposed to indicate the success in installing Zend Framework, and actually the script throws an error like this:

Exception thrown trying to access Zend/Loader.php using 'use_include_path' = true. Make sure you include Zend Framework in your include_path which currently contains: .:/usr/lib/php:/usr/local/lib/php

Which is why I tried modifying .htaccess

Does anyone know if I'm doing things wrong (obviously yes)? What is the right way to modify the htaccess file so that `/usr/lib/php and /usr/local/lib/php are included as well?

Also I've read that when you include a htaccess you must include also a .htaccess file to every subdirectory that makes an include. Most of my php scripts are directly in the public folder, but still I have many of them on subdirectories as well. How am I supposed to proceed?

I made some changes following Mike's advise and included the whole custom path like this:

$libreria='Zend/ZendFramework/library/Zend/Loader';

then I looked at php.info and it still doesn't show any changes to include_path. Additionally, I noticed that the error in the test I'm running to check if ZendFramework is installed is telling me there's a class Loader.php in the Zend folder, which is actually there, but still nothing gets loaded.

Ok so I did a couple of test to see what's going wrong, since the Zend Framework seems to load ok. First I added this code to the file 'libreria.php' which sets the include path (apparently alright, since the library is loaded). I did this:

$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";

And as a result, it outputs: "Error al cargar la librería".

I also set up a tiny test to see if there's something wrong with the case sensitivity. On some of the pages that are having trouble, I put this code inmediately after including the header and the library:

//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!');

And it does not die, so it's ok. (If I get it right the result would be different if there was a slight difference in my file names, as are seen on the browser address, and as are seen by the server, but maybe I'm wrong).

Then, there's something going on with the way I call the Autoloader.php class, but I don't see a different way of calling it than the static method on Zend's introduction to Autoloader documentation, where it says 'Autoloader, basic usage'

Upvotes: 0

Views: 1331

Answers (1)

Mike Brant
Mike Brant

Reputation: 71422

.htaccess is probably not the place to make this change, as it will be more difficult to append the new path you want to include to the existing. What you did was overwrite all the include paths with just the one you specified in .htaccess. This blowd things up.

If you look at the 2nd line of the PHP code you included, it shows you how to append to the include path (by getting the current path and appending a new path to it.) Just do similar for the path you want to include.

Upvotes: 1

Related Questions