Recently I have started learning codeigniter framework. I am facing a problem in including files from another folder. In my view folder, i have two folders named patient and includes. This is like below
views
includes - it has two folders (front & back) - back folder has a file head.php.
patients - it has a file patient.php
now I want to include head.php in patient.php.
when I use (include 'D:\XMPP\htdocs\codeigniter\application\views\includes\back\head.php'), it works.
but when I use (include '../includes/back/head.php'), it doesn't work.
how to make the 2nd option work?
Thank you.
try this route - includes\back\head.php
<?php include VIEWPATH . "includes\back\head.php"; ?>
Related
I just started creating a website at my home.
Absolutely, I must have these two pages to finish my website rapidly:- footer.php, header.php.
So I created those pages & put some contents. Also created an index page as index.php inside the htdocs folder.
Then I did include the header & footer pages inside the index.php page by using these following codes.
<?php include 'header.php'; ?>
<?php include 'footer.php'; ?>
Undoubtedly, they worked fine without any trouble.
Then I created a directory as account inside the htdocs.
Now I've a login.php page inside the account directory (/account/login.php).
Repeatedly I used those same codes to include the header & footer in the login page. But they didn't work! I saw nothing is happening. If I create the login.php page inside of the htdocs folder (not in htdocs/account/), so it works.
So, how can I include them while the login page is in account directory?
When creating sub directories and including files it is always simpler to use absolute file paths.
The path with reference to root directory is called absolute (https://www.website.com/modules/header.php), you can even remove the domain and just have /modules/header.php. The path with reference to current directory is called relative (../images/phone.png). The ../ indicates that the URL points to the directory above the current folder.
Please see answers relating to a similar question here: difference-between-relative-path-and-absolute-path-in-javascript
I think it's a file path problem,you can use this code:
<?php include '../header.php' ?>
<?php include '../footer.php' ?>
Load the file of the first level directory。
I would like to include several file in Magento 2 in one phtml file.
The project was in laravel at first and looks like this :
https://i.imgur.com/XpUbynf.png
So now I need to import all the project in a Magento 2 project but the semantic is different.
I have tried this so far but doesnt work :
https://i.imgur.com/hewweJg.png
The files I'm trying to call are in a subfolder and the path of these files is :
Wo/EyeTest/view/frontend/templates/eyetestSteps
with other subfolders like
Wo/EyeTest/view/frontend/templates/eyetestSteps/step1/
Wo/EyeTest/view/frontend/templates/eyetestSteps/step2/
Do you have any idea how can I do this ? When the file is in the same directory, there is no problem, it's display, and I guess I'm writting the path badly.
Thanks
Please use the below path for this:
<?php echo $this->getLayout()->createBlock("Magento\Framework\View\Element\Template")->setTemplate("Wo_EyeTest::eyetestSteps/step1/_instructions.phtml")->toHtml(); ?>
I just started creating a website at my home.
Absolutely, I must have these two pages to finish my website rapidly:- footer.php, header.php.
So I created those pages & put some contents. Also created an index page as index.php inside the htdocs folder.
Then I did include the header & footer pages inside the index.php page by using these following codes.
<?php include 'header.php'; ?>
<?php include 'footer.php'; ?>
Undoubtedly, they worked fine without any trouble.
Then I created a directory as account inside the htdocs.
Now I've a login.php page inside the account directory (/account/login.php).
Repeatedly I used those same codes to include the header & footer in the login page. But they didn't work! I saw nothing is happening. If I create the login.php page inside of the htdocs folder (not in htdocs/account/), so it works.
So, how can I include them while the login page is in account directory?
When creating sub directories and including files it is always simpler to use absolute file paths.
The path with reference to root directory is called absolute (https://www.website.com/modules/header.php), you can even remove the domain and just have /modules/header.php. The path with reference to current directory is called relative (../images/phone.png). The ../ indicates that the URL points to the directory above the current folder.
Please see answers relating to a similar question here: difference-between-relative-path-and-absolute-path-in-javascript
I think it's a file path problem,you can use this code:
<?php include '../header.php' ?>
<?php include '../footer.php' ?>
Load the file of the first level directory。
Thanks for reading!
I am managing a header with links using a PHP include. It is within a folder /includes/header.php.
Here's an example of what header.php looks like:
<nav>
<ul>
<li>Home</li>
<li>Page</li>
</ul>
</nav>
When I add the include to a file within the root directory, like /index.php, I add it like so: <?php include_once("header.php"); ?>. This all works fine, and the links point where they need to.
When I do the same thing but with a file in a subdirectory, for instance a file called /foo/page.php I will add the include like this: <?php include_once("../includes/header.php"); ?> - this way it grabs the file correctly.
My problem is that all of the links in the header.php file aren't going where I want them to. I found some information about using a set environment function in .htaccess, but I don't know what to make of it.
If you have an answer to this problem I'd love to hear it! Thanks!
Start all the links in the header from the root web directory.
Just do;
"/index.html"
"/subdirectory/link.html"
So basically just start all the links with a forward slash, as without it, it will look for the page within its current directory.
You can set the base url in your HTML head.
Store the base url of your application in a config file or database and then use it to build absolute links not relative ones. For example you have a file like config.php:
<?php
$baseUrl = "http://yourdomain/yourapp/";
And in header.php:
<?php include_once("config.php"); ?>
Page
It may seem inconvenient having to edit a file in case you move your application, but this way your links will work in any directory any time, and as your application grows there will be some other things like DB access that also have to be changed if you move your application, and can be stored in the same config file.
Hello I'm having my first serious go with PHP to create a sample script for my self. It has a basic structure, in my root folder I have:
index.php
core folder (holds most of my php function files)
includes (holders my header.php and footer.php)
sites - (sites has 3 further folders site A, B, C)
CSS
js
All pages are made up by taking a header.php and footer.php from the includes folder and then each page has its own content in the middle. The header.php contains (as well as basic html and links to javascripts stylesheets ect) includes from core folder like so:
include_once '/core/connect.php';
Now these all work great using the index.php which provides links to the 3 different sections of the site, sitea, siteb and sitec.
But when you navigate out of the document root to say /sites/sitea/index.php all those links are now broken.
What is the best way to go about building the links in the header.php section so they are relative site wide no matter which folder you are in?
The idea behind this is that you do only have ONE file for each process.
So process all pages through index.php
index.php would contain, for example,
require('header.php');
include('content.php');
require('footer.php');
That way, it won't break the site if your content doesn't show.
Your index is always loaded from the same path, so header/footer wouldn't change. Just content.
When you're including you want to use a real path, not a relative path...
require_once ($_SERVER['DOCUMENT_ROOT'].'/includes/header.php');
/* something happens here */
require_once ($_SERVER['DOCUMENT_ROOT'].'/includes/footer.php');
The best way is to always use physical path from wherever you are - this way every page that include other page with includes won't get break:
PHP 5.2 and down:
require(dirname(__FILE__) . '/core/connect.php');
PHP 5.3 and above
require(__DIR__ . '/core/connect.php');