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

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

How to include a file, inside subdirectory in Codeigniter 4 Views

问题

我想要包含一个文件。我知道如果文件与要包含它的文件在同一个目录中,例如

  1. .
  2. ├── about.php
  3. ├── admin
  4. ├── customer.php
  5. ├── detailorder.php
  6. ├── footer.php
  7. ├── header.php
  8. ├── index.php
  9. ├── inventory.php
  10. ├── laporan
  11. ├── inventory.php
  12. ├── omset.php
  13. ├── pembatalan.php
  14. ├── penjualan.php
  15. ├── produksi.php
  16. └── profit.php
  17. ├── login.php
  18. ├── checkout.php
  19. ├── detail_produk.php
  20. ├── footer.php
  21. ├── header.php
  22. ├── index.php
  23. └── 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

  1. .
  2. ├── about.php
  3. ├── admin
  4. ├── customer.php
  5. ├── detailorder.php
  6. ├── footer.php
  7. ├── header.php
  8. ├── index.php
  9. ├── inventory.php
  10. ├── laporan
  11. ├── inventory.php
  12. ├── omset.php
  13. ├── pembatalan.php
  14. ├── penjualan.php
  15. ├── produksi.php
  16. └── profit.php
  17. ├── login.php
  18. ├── checkout.php
  19. ├── detail_produk.php
  20. ├── footer.php
  21. ├── header.php
  22. ├── index.php
  23. └── 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:

  1. <?= $this->include('admin/header.php') ?>
英文:

Provide the full path based on the Views folder, like so:

  1. &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:

确定