Include Bootstrap in a PHP application - php

I'm learning PHP / HTML / CSS. Today I want use Bootsrap.
I use a basic HTML5 template called index.php In this file I want include a footer like this:
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="ressources/bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="ressources/css/style.css">
<script type='text/javascript' src="ressources/script/jquery.js"></script>
<script type='text/javascript' src="ressources/bootstrap/js/bootstrap.js"></script>
<title>Index</title>
</head>
<body>
<div id="wrap">
<p>test</p>
</div>
<?php include('includes/footer.php'); ?>
</body>
</html>
But I dont see my footer in my page. I just put an "Hello World" in my footer.php

Related

How to include file php

I have a problem with including a php file
PagePrevie.php :
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<link rel="stylesheet" href="Style/css/bootstrap.min.css" />
<script src="Style/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="Style/css/Header-Picture.css">
<link rel="stylesheet" href="Style/css/Footer-with-logo.css">
<title></title>
</head>
<body class="container lg-warning">
<?php
include 'include/LogoUMBB.php';
include 'include/Header.php';
?>
<div class="container bg-success text-primary" style="width:500px;padding: 20px;">
</div>
<br />
<?php
include 'include/Footer.php';
?>
</body>
</html>
The problem is that this file is located in a directory that contains other web page with the same code
And here is the structure of files:
PHP told you your path is incorrect, add "../" so you get correct include path.
include '../include/LogoUMBB.php';
include '../include/Header.php';
include '../include/Footer.php';

when i normally run html bootstrap enabled code, it shows proper output but when i load it using codeigniter view it shows different output

This is my directory:
miuse/application
miuse/application/views/templates/header.php
miuse/bootstrap/css
miuse/bootstrap/js
miuse/bootstrap/fonts
This is my controller code:
<?php
class page extends CI_controller{
public function view($page= 'home')
{
if(!file_exists(APPPATH.'views/pages/'.$page.'.php'))
{
show_404();
}
$data['title']='Moodlist home';
$this->load->view('templates/header', $data);
}
}
?>
This is my view code:
<!DOCTYPE html>
<html lang="en">
<head>
<title>
<?php echo $title; ?>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="http://localhost/miuse/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="header.css" type="text/css">
</head>
<body>
<header class="container">
<div class="row">
<h1 class="col-sm-4">List</h1>
<nav class="col-sm-8 text-right">
<p>Home</p>
<p>Category</p>
<p>About us</p>
</nav>
</div>
</header>
</body>
</html>
when i run my view normally in a browser it shows proper output but when i load it with codeigniter view then it shows different output which i dont want.
I guess your header.css file is not being loaded.
Put the header.css file in miuse/bootstrap/css directory.
And change your code from,
<link rel="stylesheet" href="header.css" type="text/css">
to
<link rel="stylesheet" href="http://localhost/miuse/bootstrap/header.css" type="text/css">
When loading css and other stuff I would recommend using base_url() in your head area
<head>
<link rel="stylesheet" type="text/css" href="<?php echo base_url('bootstrap/css/bootstrap.css');?>">
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/header.css');?>">
</head>
Make sure you have set the base url in config.php and autoload the url helper.

Html and Php image not showing online but showing in localhost

The file location of the image is correct and it displays on localhost however doesn't online, how would i be able to get this to work?
I have tried changing the images from png to jpg and using different images and changing the file locations and then updating that on the code however it still does not display the image
<!DOCTYPE HTML>
<html>
<head>
<title>KMS</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>
</head>
<body id="wrapper">
<div id="header">
<!--Logo-->
<div id="Logo">
</div>
<!--Logo-->
<!--Menu Buttons-->
<?php include 'menu.php';?>
<!--Menu Buttons-->
</div>
<div id="hContent">
<!--Frames--====================================================================-->
<div id="hFrames">
<!--Information go below-->
<div id="infoCon1">
<img id="kms_img" src="Images/Kmsproductsinformation.jpg" style="width:850px;"/>
<b />
<b />
</div>
<!--Information end-->
</div>
</div>
</div>
<!--
footer
-->
</body>
</html>
Try <img id="kms_img" src="images/kmsproductsinformation.jpg" style="width:850px;"/> and ensure that your images directory and kmsproductsinformation.jpg file are in lowercase.
You've got something funny going on with your DIVS. You have what looks like two additional close DIV tags () towards the end of your file - I'd start by fixing those up.
Having said that it also shouldn't really matter if it's localhost or not, or whether it's jpg or png but PNG would be better if you're setting it to a non-100% width.
Try something basic without all the DIVS or your menu.php file and see if that works.
<!DOCTYPE HTML>
<html>
<head>
<title>KMS</title>
<link rel="stylesheet" type="text/css" href="style.css">
<meta charset="UTF-8">
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>
</head>
<body id="wrapper">
<img id="kms_img" src="Images/Kmsproductsinformation.jpg" />
</body>
</html>

How to apply css style in codeigniter

I am having trouble with applying CSS style in my view.
I have set base_url in config.php also..
config['base_url']='http://localhost/test_project/'
My code is
<html>
<head>
<title>Untitled Document</title>
<link type="text/css" href="<?php echo base_url()?> css/mycss.css" >
</link>
</head>
<body>
<p> This is test.</p>
</body>
</html>
My CSS code is
p
{
color:#0066CC;
}
But it shows only simple text..
How to apply CSS in codeigniter....
Put the path inside the function. Include rel="stylesheet" in the link tag. You don't need the closing </link> either.
<link rel="stylesheet" type="text/css" href="<?php echo base_url('css/mycss.css'); ?>">
View the source of the page, you should see the CSS included like this
<link rel="stylesheet" type="text/css" href="http://localhost/test_project/css/mycss.css">
You need put in html tag link the attribute rel="stylesheet"
<link type="text/css" href="<?php echo base_url('css/mycss.css') ?>" rel="stylesheet" >
Check with your firebug if your css files is load fine.
You could use html tag called "base" for example:
<base href="http://url" />
In your code:
<html>
<head>
<title>Untitled Document</title>
<base href="<?php echo base_url()?>" />
<link type="text/css" href="css/mycss.css" rel="stylesheet"></link>
</head>
<body>
<p> This is test.</p>
</body>
</html>
I use the default function of codeigniter. For example:
echo link_tag('assets/css/bootstrap.css');

load whole html script in php file

Advance apologies for this noob question but i have to do it perfectly. I have made a website which are all html files and all are working fine. Now for the session handing i have to convert all the html files into php like
<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/bootstrap-min.css"/>
</head>
<body>
Body elements
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
to something like
<?php
"SESSION HANDLING PHP CODING"
echo '<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/bootstrap-min.css"/>
</head>
<body>
Body elements
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>'
?>
Hoping for best possible solution.
Thanks
You don't need to do an echo, just close the php tag with "?>":
<?php
//CODE
?>
Your Html Stuff
You really don't have to do that - you can mix HTML and PHP easily. Just surround the code with <?php and ?> tags:
<?php /* handle session here */ ?>
<!DOCTYPE HTML>
<html>
<head>
<link type="text/css" rel="stylesheet" href="css/bootstrap-min.css"/>
</head>
<body>
Body elements
<?php echo $something_you_handled_earlier; ?>
</body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
You actually need to refer session handling in PHP.
And then separate the logical php part from the HTML part as mentioned in other answers.

Categories