【发布时间】:2017-05-07 10:54:32
【问题描述】:
所需的库类似乎避开了两个 .php 文件,但找到了另一个。类(libraries/Database.php)方法在footer.php中使用。
我收到的错误是这样的:
警告:require_once(libraries/Database.php):无法打开流:第 15 行的 D:\PHP\Projects in PHP 和 MySQL\talkingspace\core\init.php 中没有这样的文件或目录
致命错误:require_once(): Failed opening required 'libraries/Database.php' (include_path='C:\xampp\php\PEAR') in D:\PHP\Projects in PHP and MySQL\talkingspace\core\第 15 行的 init.php
init.php:
<?php
// start session since we use it on every page
session_start();
// config file
require_once('config/config.php');
// helper functions
require_once('helpers/db_helper.php');
require_once('helpers/format_helper.php');
require_once('helpers/system_helper.php');
// for autoload of classes
function __autoload($class_name) {
require_once('libraries/'.$class_name.'.php');
}
index.php 文件正确显示:
<?php require('core/init.php'); ?>
<?php
// create Topic object
$topic = new Topic();
// get Template class
$template = new Template('templates/frontpage.php');
// assign vars
$template -> topics = $topic -> getAllTopics();
$template -> totalTopics = $topic -> getTotalTopics();
$template -> totalCategories = $topic -> getTotalCategories();
// display template
echo $template;
它的模板文件
<?php include 'includes/header.php'; ?>
<ul id="topics">
<?php if ($topics) : ?>
<?php foreach($topics as $topic) : ?>
<li class="topic">
<div class="row">
<div class="col-md-2">
<img class="avatar pull-left" src="images/avatars/<?php echo $topic -> avatar; ?>" />
</div>
<div class="col-md-10">
<div class="topic-content pull-right">
<h3><a href="topic.html"><?php echo $topic -> title; ?></a></h3>
<div class="topic-info">
<a href="topics.php?category=<?php echo urlFormat($topic -> category_id); ?>"><?php echo $topic -> name; ?></a> >> <a href="topics.php?user=<?php echo urlFormat($topic -> user_id) ?>"><?php echo $topic -> username; ?></a> >> Posted on: <?php echo formatDate($topic -> create_date); ?>
<span class="badge pull-right"><?php echo replyCount($topic -> id); ?></span>
</div>
</div>
</div>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php else : ?>
<p>No topics to display</p>
<?php endif; ?>
<h3>Forum Statistics</h3>
<ul>
<li>Total Number of Users: <strong>52</strong></li>
<li>Total Number of Topics: <strong><?php echo $totalTopics; ?></strong></li>
<li>Total Number of Categories: <strong><?php echo $totalCategories; ?></strong></li>
</ul>
<?php include 'includes/footer.php'; ?>
服务很好,但是类似的模板文件与另外两个 .php 文件一起失败。这是一个(register.php):
<?php require('core/init.php'); ?>
<?php
// get Template class
$template = new Template('templates/register.php');
// assign vars
$template -> title = 'Create an Account';
// display template
echo $template;
它的模板是:
<?php include 'includes/header.php'; ?>
<form role="form" enctype="multipart/form-data" method="post" action="register.php">
<div class="form-group">
<label>Name<sup>*</sup></label>
<input type="text" class="form-control" name="name" placeholder="Enter Your Name">
</div>
<div class="form-group">
<label>Email Address<sup>*</sup></label>
<input type="email" class="form-control" name="email" placeholder="Enter Your Email Address">
</div>
<div class="form-group">
<label>Choose Username<sup>*</sup></label>
<input type="text" class="form-control" name="username" placeholder="Create A Username">
</div>
<div class="form-group">
<label>Password<sup>*</sup></label>
<input type="password" class="form-control" name="password" placeholder="Enter A Password">
</div>
<div class="form-group">
<label>Confirm Password<sup>*</sup></label>
<input type="password" class="form-control" name="password2" placeholder="Enter Password Again">
</div>
<div class="form-group">
<label>Upload Avatar</label>
<input type="file" name="avatar">
<p class="help-block"></p>
</div>
<div class="form-group">
<label>About Me</label>
<textarea id="about" rows="6" cols="80" class="form-control" name="about" placeholder="Tell us about yourself (Optional)"></textarea>
</div>
<input name="register" type="submit" class="btn btn-default" value="Register" />
</form>
<?php include 'includes/footer.php'; ?>
请帮忙。我尝试了这里发布的一些解决方案,但无济于事。 XAMPP 文件夹是 C:\ 上的默认文件夹,项目文件夹位于另一个驱动器上。
【问题讨论】:
-
可能是权限问题
-
问题是相同的代码适用于一个 .php 文件,而不适用于另外两个。如果这有助于确定问题,那么讲师也遇到了同样的问题,然后他替换了模板的 html 代码,问题就消失了。
-
在 init.php 中?我应该把它放在哪里?
-
将 require_once 更改为 require "/path/to/file"
-
你能把代码贴出来吗?
标签: php