₦airaland Forum

Welcome, Guest: RegisterLoginWith GoogleTrendingRecentNew

Stats: 3,330,924 members, 8,447,779 topics. Date: Sunday, 19 July 2026 at 12:07 AM

Toggle theme

[PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? - Programming - Nairaland

Nairaland ForumScience/TechnologyProgramming[PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? (1313 Views)

1 Reply (Go Down)

[PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by Nobody: 5:43am On Nov 22, 2018
I want to REQUIRE a footer that exist in another folder.
I tried require "../footer.php",
but this isn't working.
What am I doing wrong?
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by hollyfat(m): 5:52am On Nov 22, 2018
Are you sure that the footer.php is in the folder you are referencing?
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by Nobody: 6:41am On Nov 22, 2018
hollyfat:
Are you sure that the footer.php is in the folder you are referencing?
Yes, it is.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by talk2hb1(m): 7:31am On Nov 22, 2018
branhampaul:
I want to REQUIRE a footer that exist in another folder.
I tried require "../footer.php",
but this isn't working.
What am I doing wrong?
Try require"footer.php"
I guess they are both in the same directory llevel.
A quick boner:
That ../ means hey php go up a directory from this current directory and include a file named footer.php here because it is required. But if the footer.php is in a folder as i assumed possibly in an include directory and at a upper level from where you are including it just do require"../include/footer.php
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by holuphisayor(m): 7:39am On Nov 22, 2018
You are not referencing any folder with that require statement. What's your project structure or better still learn how to autoload ur files.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by webapi: 8:13am On Nov 22, 2018
branhampaul:
I want to REQUIRE a footer that exist in another folder.
I tried require "../footer.php",
but this isn't working.
What am I doing wrong?
Why are you using REQUIRE? instead use include....
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by ensodev(m): 8:53am On Nov 22, 2018
You have to show the structure of your folder.
Meanwhile include is what you should use unless your footer file has a method that you have been refering to in some part of your folder.

Show us something
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by afonja112: 9:12am On Nov 22, 2018
Let me explain something:

+ resources
++ views
+++ header.php
+++ footer.php
+ app
++ template.php
+ index.php

Let us assume you load the index folder, and want to include the app/template.php, here is what most people will do
include "app/template.php"; //relative addressing

Here is what i will do
include __DIR__."/app/template.php"; //absolute addressing

So let us now assume that inside the template.php you wish to include header.php, you best best is this

include __DIR__."/../resources/views/header.php"; //this is absolute addressing still


If you want to include footer.php inside header.php, then is best to do
include __DIR__."/footer.php";

If you follow this guideline, you will get it better.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by Nobody: 4:01pm On Nov 22, 2018
webapi:
Why are you using REQUIRE? instead use include....
Nope, I prefer REQUIRE, INCLUDE makes the page work even when that code isn't present, this may distort the workflow.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by ensodev(m): 4:06pm On Nov 22, 2018
afonja112:
Let me explain something:

+ resources
++ views
+++ header.php
+++ footer.php
+ app
++ template.php
+ index.php

Let us assume you load the index folder, and want to include the app/template.php, here is what most people will do
include "app/template.php"; //relative addressing

Here is what i will do
include __DIR__."/app/template.php"; //absolute addressing

So let us now assume that inside the template.php you wish to include header.php, you best best is this

include __DIR__."/../resources/views/header.php"; //this is absolute addressing still


If you want to include footer.php inside header.php, then is best to do
include __DIR__."/footer.php";

If you follow this guideline, you will get it better.
Nice one
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by afonja112: 6:36pm On Nov 22, 2018
I have built frameworks before, and I know this is the technique used by most frameworks to load stuffs so that you dont enter wahala with require/include things.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by Nobody: 6:57pm On Nov 22, 2018
Thanks all, I have figured it out.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by afonja112: 8:54pm On Nov 22, 2018
Very good, how did you do it? So that others can learn.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by Nobody: 10:52pm On Nov 22, 2018
afonja112:
Very good, how did you do it? So that others can learn.
my original code was correct, I was the one peddling with the wrong PHP file.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by afonja112: 9:26am On Nov 23, 2018
Great that you have solved it. I will also use this opportunity to chip in a few things:

1. For developers, try to use simple directory structures.
2. Use simple naming conventions e.g. if you are like me, just name your files with lowercase and be consistent with it. Or name your files with camelCase - and require it that way.

Many developers enter a jam for this, see this:

+ index.php
+ Head.php
+ Foot.php


inside index.php, you now do this
include 'head.php';
include 'foot.php';

This will work on windows and mac, but by the time you get to a live server e.g. linux, you will start getting file not found, and start wondering if it is your village people that are chasing you.

I don wake dey go be that.
Re: [PHP] How Can I Use REQUIRE For A Footer That Exist In Another Folder? by ensodev(m): 11:11pm On Nov 23, 2018
afonja112:
Great that you have solved it. I will also use this opportunity to chip in a few things:

1. For developers, try to use simple directory structures.
2. Use simple naming conventions e.g. if you are like me, just name your files with lowercase and be consistent with it. Or name your files with camelCase - and require it that way.

Many developers enter a jam for this, see this:

+ index.php
+ Head.php
+ Foot.php


inside index.php, you now do this
include 'head.php';
include 'foot.php';

This will work on windows and mac, but by the time you get to a live server e.g. linux, you will start getting file not found, and start wondering if it is your village people that are chasing you.

I don wake dey go be that.
NICE ALERT.. .Red flag for the wise. Great info!!!!!!!!
1 Reply

Do Game Developers Exist In Nigeria?Php How To Determine If A Quantity Is Declining?Help on how to design header, footer and add width234

In Need Of Software Internship PlacementJust Arrived Uk Used Toshiba Dynabook T552 Core I7 8gb Ram 500gb Hdd @cheap PricNon-availability Of Jobs In Nigeria Tech Market: Reality Or Just A Facade?