dongyong1942 2018-10-12 16:08
浏览 49

包含的函数无法在php中包含的标题和导航栏文件中工作

Am working on some website, where i have php files in includes folder and navbar, header and footer in layouts folder. When i require functions in includes folder in my index.php they work properly but when i call the same functions in header or navbar the blow with error Undefined index and the name of the function. What can i do?

Index.php:

<?php 
require("../includes/initialize.php");
require_once(LIB_PATH.DS.'session.php');    
?>

<!-- header -->
<?php 
include_layout_template('header.php'); 
include_layout_template('navbar.php'); 
?>

<?php echo output_message($message); ?>

navbar.php:

<div class="agileits_header">
    <div class="container">
        <div class="w3l_offers">
        </div>
        <div class="agile-login">
            <ul>
            <?php if(!$session->is_logged_in()): ?>
                <li><a href="register.php"> Create Account </a></li>
                <li><a href="login.php">Login</a></li>
            <?php else: ?>
                <li><a href="profile.php">Profile</a></li>
                <li><a href="logout.php">Logout</a></li>
            <?php endif; ?>
                <li><a href="contact.php">Help</a></li>
            </ul>
        </div>

This is my initialize.php file:

defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

defined('SITE_ROOT') ? null : 
    define('SITE_ROOT', DS.'xampp'.DS.'htdocs'.DS.'supermarket');

defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

// load config file first
require_once(LIB_PATH.DS.'config.php');

// load basic functions next so that everything after can use them
require_once(LIB_PATH.DS.'functions.php');
require_once(LIB_PATH.DS.'validation_functions.php');

// load core objects
require_once(LIB_PATH.DS.'database.php');
require_once(LIB_PATH.DS.'database_object.php');
require_once(LIB_PATH.DS.'pagination.php');


// load database-related classes
require_once(LIB_PATH.DS.'user.php');
require_once(LIB_PATH.DS.'admin.php');
require_once(LIB_PATH.DS.'seed.php');
require_once(LIB_PATH.DS.'comment.php');

?>

  • 写回答

1条回答 默认 最新

  • dqrfdl5708 2018-10-12 16:30
    关注

    Always include all files with absolute path. Don't use '..' for include files.

    try this

    define('SITE_ROOT', dirname(__FILE__));
    

    OR

    define('ROOTPATH', __DIR__);
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度