英文:
How to include a file, inside subdirectory in Codeigniter 4 Views
问题
我想要包含一个文件。我知道如果文件与要包含它的文件在同一个目录中,例如
.
├── about.php
├── admin
│ ├── customer.php
│ ├── detailorder.php
│ ├── footer.php
│ ├── header.php
│ ├── index.php
│ ├── inventory.php
│ ├── laporan
│ │ ├── inventory.php
│ │ ├── omset.php
│ │ ├── pembatalan.php
│ │ ├── penjualan.php
│ │ ├── produksi.php
│ │ └── profit.php
│ ├── login.php
├── checkout.php
├── detail_produk.php
├── footer.php
├── header.php
├── index.php
└── welcome_message.php
上述目录结构位于CI4项目的"Views"文件夹中。我可以从index.php
文件中包含header.php
文件,也可以从admin/customer.php
文件中包含header.php
文件,因为header.php
文件与要包含它的文件位于同一个目录中。
但是,如何在admin/header.php
文件中包含admin/laporan/inventory.php
文件中的header.php
文件呢?
我尝试过../header.php
和../admin/header.php
,但都没有成功。
英文:
I want include a file. I know I can include a file if the file is in same directory, for example
.
├── about.php
├── admin
│ ├── customer.php
│ ├── detailorder.php
│ ├── footer.php
│ ├── header.php
│ ├── index.php
│ ├── inventory.php
│ ├── laporan
│ │ ├── inventory.php
│ │ ├── omset.php
│ │ ├── pembatalan.php
│ │ ├── penjualan.php
│ │ ├── produksi.php
│ │ └── profit.php
│ ├── login.php
├── checkout.php
├── detail_produk.php
├── footer.php
├── header.php
├── index.php
└── welcome_message.php
tree directory above is in Views folder of CI4 project. I can include the header.php
file from index.php
file also i can include header.php
file from admin/customer.php
that because header.php
file is in the same directory as the file want to include.
But, how to include header.php
file in admin/header.php
to file in admin/laporan/inventory.php
I have tried ../header.php
and ../admin/header.php
but it didn't work
答案1
得分: 1
Provide the full path based on the Views
folder, like so:
<?= $this->include('admin/header.php') ?>
英文:
Provide the full path based on the Views
folder, like so:
<?= $this->include('admin/header.php') ?>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论