如何在 Codeigniter 4 视图中包含子目录内的文件

huangapple go评论63阅读模式
英文:

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:

&lt;?= $this-&gt;include(&#39;admin/header.php&#39;) ?&gt;

huangapple
  • 本文由 发表于 2023年5月21日 14:23:20
  • 转载请务必保留本文链接:https://go.coder-hub.com/76298560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定