php 原生模板 include 报错

surzace

问题描述

php 原生模板 include 报错

程序代码

<!DOCTYPE html>
<html lang="<?= trans('l') ?>">
<?php include '../layout/header.html'; ?>
<body>
<div class="layui-layout layui-layout-admin">
    <?php include '../layout/menu.html' ?>
    <div class="layui-body">
        <div style="padding: 16px;"></div>
    </div>
    <?php include '../layout/password.html' ?>
</div>
<?php include '../layout/script.html' ?>
</body>
</html>

报错信息

ErrorException: include(../layout/header.html): Failed to open stream: No such file or directory in D:\webman\sjk\app\view\shop\index.html:3
Stack trace:
#0 D:\webman\sjk\app\view\shop\index.html(3): support\App::{closure}(2, 'include(../layo...', 'D:\\webman\\sjk\\a...', 3)
#1 D:\webman\sjk\app\view\shop\index.html(3): include()
#2 D:\webman\sjk\vendor\workerman\webman-framework\src\support\view\Raw.php(70): include('D:\\webman\\sjk\\a...')
#3 D:\webman\sjk\support\helpers.php(201): support\view\Raw::render('shop/index', Array, '', '')
#4 D:\webman\sjk\app\controller\ShopController.php(11): view('shop/index')
#5 D:\webman\sjk\vendor\workerman\webman-framework\src\App.php(319): app\controller\ShopController->index(Object(support\Request))
#6 D:\webman\sjk\vendor\workerman\webman-framework\src\App.php(141): Webman\App::Webman\{closure}(Object(support\Request))
#7 D:\webman\sjk\vendor\workerman\workerman\Connection\TcpConnection.php(646): Webman\App->onMessage(Object(Workerman\Connection\TcpConnection), Object(support\Request))
#8 D:\webman\sjk\vendor\workerman\workerman\Events\Select.php(311): Workerman\Connection\TcpConnection->baseRead(Resource id #140)
#9 D:\webman\sjk\vendor\workerman\workerman\Worker.php(1488): Workerman\Events\Select->loop()
#10 D:\webman\sjk\vendor\workerman\workerman\Worker.php(1405): Workerman\Worker::forkWorkersForWindows()
#11 D:\webman\sjk\vendor\workerman\workerman\Worker.php(560): Workerman\Worker::forkWorkers()
#12 D:\webman\sjk\vendor\workerman\webman-framework\src\support\App.php(131): Workerman\Worker::runAll()
#13 D:\webman\sjk\start.php(4): support\App::run()
#14 {main}

截图报错信息里报错文件相关代码

截图

操作系统及workerman/webman等框架组件具体版本

Windows 11
PHP8.3.8
webman 1.5.5
webman-framework 1.5.19

438 3 0
3个回答

walkor 打赏

用绝对路径

  • surzace 2024-06-25

    这样确实可以 但是如果部署的话不是要每个都改一遍?有没有什么简便的方法

  • Madman 2024-06-25

    方法一:定义一个函数
    方法二:配置一个全局变量

tanhongbin

你这么写 啥框架你也找不到

  • surzace 2024-06-25

    那你说该怎么写 不用绝对路径 用/开头的也行

  • tanhongbin 2024-06-25

    你就没想过 引入接口然后接口渲染这里嘛

  • surzace 2024-06-25

    为啥用模板 就是不想用接口 要是搞接口还不如搞成前后端分离了

ichynul

相对路径是从php命令行运行的地方算

  • 暂无评论
×
🔝