-1

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!

Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
Abhishek Joshi
  • 95
  • 2
  • 13

3 Answers3

2

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');
Rejoanul Alam
  • 5,435
  • 3
  • 39
  • 68
0

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'; ?>

Shaiful Islam
  • 7,034
  • 12
  • 38
  • 58
  • those must work.where is your sidebar.php file located? – Shaiful Islam Oct 14 '16 at 23:48
  • it is located in the same view directory where index.php page is located ! the reason i think it is happening because one of my team member actually made some changes in loader.php file and now i am facing such issues bcz he forgot where he made changes!! – Abhishek Joshi Oct 14 '16 at 23:51
  • no. include is php basic function.it does include.check the spelling and case sensitive. – Shaiful Islam Oct 14 '16 at 23:53
  • There is a troubleshooting g checklist for this kind of mistakes : http://stackoverflow.com/questions/36577020/php-failed-to-open-stream-no-such-file-or-directory – Vic Seedoubleyew Oct 15 '16 at 11:56
  • some thing I said in the answer.I think u did not understand the answer. – Shaiful Islam Oct 15 '16 at 13:40
0

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

Brad
  • 1,685
  • 1
  • 27
  • 38