链接自定义函数php

时间:2017-03-24 16:48:51

标签: php html

我对PHP更新一点。我的问题是,我的index.php链接到config.php。但我有一个链接到common.php的自定义函数。

//THIS IS THE INDEX.PHP
<?php

if ( file_exists( 'lib/config.php' ) )
  require_once 'lib/config.php';
else
  echo "Whoops, something went wrong, we're working on a fix.";

html5_page_pre(
  "Yummy Tummy",
  array('style.css')
);

html5_page_post();
?>

如果我将其更改为lib / common.php,由于缺少config.php而导致页面加载错误并且识别出html5_page_pre。该函数在common.php中定义,如何让它保留config.php并且仍然具有链接功能?由于config.php包含用于登录等的数据库的主干

//THIS IS THE CONFIG.PHP
<?php
// database settings
$host = 'localhost'; // database address
$dn = 'test_proj'; // database name
$user = 'test_proj'; // database username
$pass = '******'; // database password
$charset = 'utf8'; // character set

// Root of the website with leading "/"
// e.g: for http://webhost.com/subdomain/my_site, set to "/subdomain/my_site"
$site_root = "/Project/";

// set default timezone
date_default_timezone_set('America/Toronto');

/* DO NOT TOUCH BELOW THIS LINE UNLESS YOU ARE A DELEVOPER */
// site's absolute path on the filesystem
$doc_root = $_SERVER[ 'DOCUMENT_ROOT' ];

if ( file_exists( $doc_root . $site_root . 'lib/common.php' ) )
  require_once $doc_root . $site_root . 'lib/common.php';
else
  echo "Whoops, something went wrong, we're working on a fix.";
?>

正如您所看到的,我最后还将common.php链接到config.php。它是否应该没有错误加载页面?我不明白为什么在这种情况下无法识别自定义功能。

谢谢!

1 个答案:

答案 0 :(得分:0)

将需要从配置移动到索引。

<?php

require_once 'lib/config.php';
require_once 'lib/common.php';

html5_page_pre(
  "Yummy Tummy",
  array('style.css')
);

html5_page_post();