Search code examples
phphtmlcodeigniterframeworkscodeigniter-4

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


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


Solution

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

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