0

I want to learn and work with initialize.php so I try to build simple php file like index.php and just to see if it call to hello.php I got some truble on my local host using windows xp.

the details are:

http://127.0.0.1/www/oop/shape2/index.php the file index.php

<?php
    defined('DS') ? null : define('DS', '/');
    defined('SITE_ROOT') ? null :defined('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);
    defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

    echo (LIB_PATH.DS.'hello.php');
    require_once(LIB_PATH.DS.'hello.php');
?>

the output is:

SITE_ROOT/includes/hello.php

http://127.0.0.1/www/oop/shape2/includes/hello.php the file hello.php

<?php
 echo ('hi');
 ?>

if i run it I got hi

here is my local folder on windows: C:\Program Files\Zend\Apache2\htdocs\www\oop\shape2

what shell I do slove the problem. Thx

4

1 回答 1

1

On the second line, you should change

defined('SITE_ROOT') ? null :defined('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);

to

defined('SITE_ROOT') ? null :define('SITE_ROOT', $_SERVER['DOCUMENT_ROOT']);

You were calling the defined function rather than the define function, meaning you never actually created the SITE_ROOT constant.

于 2012-06-19T12:49:33.690 回答