facing an issue while includeing a file in codeigniter - php

i have include a file sidebar.php in view of index page but it gives me a error like these
A PHP Error was encountered
Severity: Warning
Message: include(sidebar.php): failed to open stream: No such file or
directory
Filename: core/Loader.php(829) : eval()'d code
Line Number: 38
and other error is these
A PHP Error was encountered
Severity: Warning
Message: include(): Failed opening 'sidebar.php' for inclusion
(include_path='.;C:\xampp\php\PEAR')
Filename: core/Loader.php(829) : eval()'d code
Line Number: 38
the file sidebar.php is in the same directory and the code is as follows:
<div class="col-md-3 left_col">
<div class="left_col scroll-view">
<!-- sidebar menu -->
<?php include 'sidebar.php'; ?>
<!-- /sidebar menu -->
</div>
</div>
i am novice here so please forgive!

Use this instead of using raw php function (assuming your sidebar.php is in same directory where you will use this)
$this->load->view('sidebar');

They way you including file sidebar.php should be root folder where main index.php located.
Or you should use full file path C:\xampp\htdocs\.....YOUR PROJECT FILE DIRECToRY\sidebar.php
Or You can Use FCPATH APPPATH to get the filepath
Example
if your sidebar.php is in root folder <?php include FCPATH.'sidebar.php'; ?>
if it is inside application folder use <?php include APPPATH.'sidebar.php'; ?>

Load your sidebar in your controller
public function sources()
{
$this->load->view("pages/header/head", $data);
$this->load->view("pages/sidebar"
$this->load->view("admin/main");
$this->load->view("pages/footer/footer");
}
Of course adapted to your code

Related

Message: Undefined property: CI_Loader::$general_settings

Framework: codeigniter
Actually am facing some issue. I created an admin panel where I can change the logo of the site and it works in the panel but if I load the logo on the website index page but if I load logo in website index page then it will returns this error.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI_Loader::$general_settings
Filename: views/index.php
Line Number: 6
Backtrace:
File: C:\xampp\htdocs\hrdk\application\views\index.php
Line: 6
Function: _error_handler
File: C:\xampp\htdocs\hrdk\application\controllers\Home.php
Line: 8
Function: view
File: C:\xampp\htdocs\hrdk\index.php
Line: 315
Function: require_once
http://localhost/hrdk/" alt="Logo" >
Website index page code is here
<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<img src="<?= base_url($this->general_settings['logo']); ?>" alt="Logo" >
</body>
</html>
website index page controler code is here
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
public function index()
{
$this->load->view('index');
}
}

Failed opening and inclusion

I really hope that someone can help me, because I have tried everything now in 4 days, and I am just stuck. I had a question with this before that did not get solved.
When I click one of my buttons "register" I get the following error:
Warning: include(resources/includes/header.html): failed to open stream: No such file or directory in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Warning: include(): Failed opening 'resources/includes/header.html' for inclusion (include_path='.:/Applications/MAMP/bin/php/php5.6.2/lib/php') in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5
Here is the relevant code:
header.html:
<!-- 1 button in the header -->
<li>
Register 1 <!-- Error -->
</li>
<!-- registernumbers.php is called fine. I can see my <h1> and <h2> text -->
registernumbers.php:
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php include 'resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
My folder structure is looking like this:
../../php/resources/includes/header.html
Is working, but the CSS is ofcourse not called.
resources/includes/header.html
This is the correct path, but here I get the error
<?php include(ROOT_PATH . 'resources/includes/header.html'); ?>
Does not work either
The path to the header is correct, and I even tried to uinstall MAMP.
When I use this:
When I put the header.html and registernumbers.php, where my index.php is, everything is working fine.
Does anybody have a clue on what I can do? I would really like to seperate my files in folders like this.
Updated code after response
<?php
if( !isset( $_SESSION ) ) session_start();
?>
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
<h1>Register Numbers</h1>
<h2>global/registernumbers</h2>
<?php define ('APP_ROOT', '/resources/includes/header.html'); ?>
// Here I do not get any errors, but the header is not called either
<?php define 'APP_ROOT', '/resources/includes/header.html'; ?>
//Parse error: syntax error, unexpected ''APP_ROOT'' (T_CONSTANT_ENCAPSED_STRING) in /Applications/MAMP/htdocs/website/php/global/registernumbers.php on line 5

Adding php to html

I added some php to some of my pages, but its not coming up on any of the pages.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('/Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
in the php file I had this.
<header>
<a href="#" class="menu-toggle">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</a>
<nav class="menu-side">
<div class="listing">
<div class="box"><a class="list" href="/"><h1>Home</h1></a></div>
<div class="box"><a class="list" href="/DayZ_Home/"><h1>DayZ</h1></a></div>
<div class="box"><a class="list" href="/Photos/"><h1>Photos</h1></a></div>
<div class="box"><a class="list" href="/Store/"><h1>Store</h1></a></div>
</div>
</nav>
</header>
This is the exact same for all my pages, and nothing is coming up.
This is the error I get:
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening '/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
Any Idea what is wrong?
Simply try this first : Remove slash in front of php in the path and run again.
If that don't work continue reading.
Let me help you as much as I can.
First thing first, this
[02-Oct-2015 22:44:59 America/Denver] PHP Warning: include(): Failed
opening'/Php/Slider.php' for inclusion
(include_path='.:/usr/php/54/usr/lib64:/usr/php/54/usr/share/pear') in
/home2/itskeega/public_html/index.php on line 14
(just stating the obvious to me) This means,
There is a FIle called 'index.php' in public_html directory
It has a function "include()" on line 14 in its code.
The include function have a path in parenthesis following it.
There is a error in that path.
Either file "Slider.php" is not there or the script can't read it.
how do i know it for sure ?
Failed opening'/Php/Slider.php' for inclusion
Why did I tell this ?
It will help to understand errors next time.
Now let's try to solve the error, what I would do first to confirm the file permissions and every other thing is
Move the file to "public_html" folder itself.
new Path will be just Slider.php (Take note of the case).
Run your script and look for errors now.
That is the simplest way to do it.
Be very very precise in the "case" becuase I see you are not using the php conventions of naming everything.
Report back with the directory structure so we can help further.
'/Php/Slider.php' I assume you have Slider.php inside Php directory, Now the correct way to include would be:
require ('../Php/Slider.php');
Which will go back first, open the Php directory folder and look for Slider.php file.
<body class="menu">
<!-- Slide bar starts here -->
<?php require ('../Php/Slider.php');?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
EDIT:
Moving forward from the comments under this answer, you stated your directory structure as:
/public_html/index.php (home page)
/public_html/Php/Slider.php
Which means the approach I stated was fine.
To go from index.php to Slider.php the way would be:
../ (Go back)
Php/ (Open the Php directory)
Slider.php (Look for Slider.php)
Hence, require ('../Php/Slider.php');
As you mentioned that you are including this file in whole project , yet you did not mention the dirctory structure . It is always better to include files with absolute path .
try as below -
<body class="menu">
<!-- Slide bar starts here -->
<?php
$file=$_SERVER['DOCUMENT_ROOT']."<--your project dir-->".'/Php/Slider.php';
require ($file);
?>
<!--Slide Bar Ends Here-->
<div class="body">
Store Comming Soon
</div>
<script src="store.js"></script>
</body>
<?php require ($_SERVER["DOCUMENT_ROOT"]."/path/to/file.php");?>
$_SERVER["DOCUMENT_ROOT"]. Makes your path start at /public_html/

How can I apply a class to a PHP line?

I have <?php get_header(); ?> for the header
and want to add in class="sticky" so that when it's parsed to HTML it will read <header class=sticky">
Where/how would I do this? Various places I've tried within the PHP line gives me an error message **Parse error: syntax error, unexpected '?' in /home2//public_html/wp-content/themes/conf-theme/page.php on line 1**
Open the header.php file and add the sticky class to
<header id="masthead" class="site-header" role="banner">
The get_header function
Includes the header.php template file from your current theme's directory.
EDIT
jQuery
<script type="text/javascript">
$(document).ready(function()
{
$("header").addClass("sticky");
});
</script>

OpenCart PHP error in VQCache file

We just launched a redesign of a client's ecommerce site running on OpenCart. We're trying to track down an error we're seeing in the Error Logs, but it's been eluding us thus far:
PHP Notice: Undefined index: route in .../vqmod/vqcache/vq2-catalog_view_theme_margaretha_template_common_header.tpl on line 360
The code on that line is:
<?php if ($this->request->get['route'] != 'common/home') { ?>
<div id="free-shipping">
<p>Free shipping on all orders!</p>
</div>
<?php } ?>
I'm not sure why this is throwing an error. Any ideas?
Change your if condition as follows:
<?php if (isset($this->request->get['route']) && $this->request->get['route'] != 'common/home') { ?>
<div id="free-shipping">
<p>Free shipping on all orders!</p>
</div>
<?php } ?>
The code may be in your theme folder's common/header.tpl or in some vqmod xml file (editing the file /vqmod/vqcache/vq2-catalog_view_theme_margaretha_template_common_header.tpl won't make any change).
Have a nice day !!

Categories