Pro PHP- Patterns, Frameworks, Testing and More

(vip2019) #1

(^218) CHAPTER 15 ■ INTRODUCTION TO THE ZEND FRAMEWORK
Test your results by visiting http://yoursite.com/asdf to make sure that you see “Rewrite
working.” If you don’t, you will need to troubleshoot mod_rewrite (see http://httpd.apache.org/
docs/2.0/mod/mod_rewrite.html for documentation on mod_rewrite).
Assuming that all went well, the next step is to start building the index.php file for real.
Clear the old file:



echo > index.php
Then create a new index.php file and include the main Zend platform include file.
pico –w index.php
<?php
define('ZFW_VERSION','1.0.3');
define('ZFW_PREFIX','/usr/share/php/ZendFramework');
define('APP_PATH', realpath(dirname(FILE). '/../'));
$paths = array(
APP_PATH,
APP_PATH. DIRECTORY_SEPARATOR. 'application'. DIRECTORY_SEPARATOR. 'models',
ZFW_PREFIX. DIRECTORY_SEPARATOR. 'ZendFramework-'. ZFW_VERSION. ➥
DIRECTORY_SEPARATOR. 'library',
get_include_path()
);
set_include_path(implode(PATH_SEPARATOR, $paths));
require_once('Zend/Loader.php');
■Note The ZFW_VERSION constant defines which version of the framework your site will use.
At this point, if everything is working properly, reloading your page will show no errors and
no content. If it’s not working, your Zend Framework setup isn’t quite right; the most likely
culprit is file permissions.
Now you can continue to build the index.php file. From this point on, when you edit the
file, you are adding content to the file, not replacing existing code.
Next, enable SPL autoloading of framework classes.
pico –w index.php
Zend_Loader::registerAutoload();
The final step is to enable exceptions. By default, the Zend Framework does not throw
exceptions. This is a security measure, designed to keep confidential information from being
displayed to the user unintentionally. However, this makes getting started with the framework
much more difficult. To enable the throwing of exceptions, you must first get a reference to the
McArthur_819-9C15.fm Page 218 Thursday, February 28, 2008 7:44 AM


Free download pdf